From 81912f1a815097fbda9de2335a9ce16681777360 Mon Sep 17 00:00:00 2001 From: Alexander Hess Date: Wed, 16 Oct 2024 11:23:54 +0200 Subject: [PATCH] Make linters check for unused function arguments --- noxfile.py | 1 + poetry.lock | 16 +++++++++++++++- pyproject.toml | 9 +++++++++ src/lalib/elements/galois.py | 2 +- src/lalib/fields/base.py | 2 +- 5 files changed, 27 insertions(+), 3 deletions(-) diff --git a/noxfile.py b/noxfile.py index 4db6f24..efb7135 100644 --- a/noxfile.py +++ b/noxfile.py @@ -208,6 +208,7 @@ def lint(session: nox.Session) -> None: "flake8-todos", "flake8-pyproject", "flake8-pytest-style", + "flake8-unused-arguments", "mypy", "pep8-naming", # flake8 plug-in "pydoclint[flake8]", diff --git a/poetry.lock b/poetry.lock index 0c5eed0..d0ee9fd 100644 --- a/poetry.lock +++ b/poetry.lock @@ -722,6 +722,20 @@ pycodestyle = "*" [package.extras] dev = ["isort[pyproject]", "pytest"] +[[package]] +name = "flake8-unused-arguments" +version = "0.0.13" +description = "flake8 extension to warn on unused function arguments" +optional = false +python-versions = "*" +files = [ + {file = "flake8-unused-arguments-0.0.13.tar.gz", hash = "sha256:c5894d294424bf7915e44dff0917222c454151016f96edc55b9f847bf307f3f7"}, + {file = "flake8_unused_arguments-0.0.13-py3-none-any.whl", hash = "sha256:df6a76b73a6ce67720332182a80f2f0a80783cab1ccae8175f39787cd3a74b31"}, +] + +[package.dependencies] +flake8 = ">3.0.0" + [[package]] name = "identify" version = "2.6.1" @@ -1728,4 +1742,4 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "a10f3c13ed0c67e6ea65500335281cd269e3efdd0fae544ad667d07637ef118f" +content-hash = "e0962e284e415b91fad954a9ca20d3dd45be434d23c63ce1e38da75f69e9557c" diff --git a/pyproject.toml b/pyproject.toml index 72c975f..51f94c3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -61,6 +61,7 @@ flake8-string-format = "^0.3" flake8-todos = "^0.3" flake8-pyproject = "^1.2" flake8-pytest-style = "^2.0" +flake8-unused-arguments = "^0.0" mypy = "^1.11" pep8-naming = "^0.14" # flake8 plug-in pydoclint = { extras = ["flake8"], version = "^0.5" } @@ -177,6 +178,7 @@ select = [ "S", # flake8-bandit => common security issues "T00", # flake8-todos => unify TODOs "T10", # flake8-debugger => no debugger usage + "U100", # flake8-unused-arguments => declared function arguments must be used # violations not covered by `ruff` below @@ -255,6 +257,12 @@ docstring-quotes = "double" inline-quotes = "double" multiline-quotes = "double" +# Plug-in: flake8-unused-arguments +# Source: https://github.com/nhoad/flake8-unused-arguments +# Make flake8-unused-arguments behave like ruff's "ARG" error code +unused-arguments-ignore-abstract-functions = true +unused-arguments-ignore-stub-functions = true + [tool.isort] # aligned with [tool.ruff.lint.isort] below @@ -347,6 +355,7 @@ select = [ # violations also covered by `flake8` above "ANN", # flake8-annotations => enforce type checking for functions + "ARG", # flake8-unused-arguments => declared function arguments must be used "B", # flake8-bugbear => bugs and design flaws "C4", # flake8-comprehensions => better comprehensions "C90", # mccabe => cyclomatic complexity diff --git a/src/lalib/elements/galois.py b/src/lalib/elements/galois.py index 11e44c6..7ea450d 100644 --- a/src/lalib/elements/galois.py +++ b/src/lalib/elements/galois.py @@ -109,7 +109,7 @@ def _to_gf2( class GF2Meta(abc.ABCMeta): """Make data type of `one` and `zero` appear to be `gf2`.""" - def __repr__(cls) -> str: + def __repr__(cls) -> str: # noqa: RUF100,U100 """Text representation for `GF2Element` and sub-classes.""" return "gf2" diff --git a/src/lalib/fields/base.py b/src/lalib/fields/base.py index 0e94569..b24ccf9 100644 --- a/src/lalib/fields/base.py +++ b/src/lalib/fields/base.py @@ -26,7 +26,7 @@ class Field(abc.ABC, Generic[T]): return self._dtype(value, **kwargs) @staticmethod - def _post_cast_filter(possible_element: T, /) -> bool: + def _post_cast_filter(possible_element: T, /) -> bool: # noqa: ARG004 """Function to filter out castable `value`s. Called after a successfull call of the `._cast_func()`.