Ruff doesn't catch undefined argument to function

954 views Asked by At

I'm not sure even if it is ruff's job to catch the undefined argument to a function, but is there a tool that does this? or is there a ruff configuration that I'm missing to add so that ruff can do this?

from typing import Optional


def my_func(bar: int, baz: int, foo: Optional[int] = None) -> int:
    if foo:
        return foo + bar + baz
    else:
        return bar + baz


my_func(foo=1, bar=2, baz=3)
my_func(bar=2, baz=3)
my_func(f=1, bar=2, baz=3) # this should have been caught by ruff, but isn't and I'm 

my ruff.toml

select = [
    "F",   # https://beta.ruff.rs/docs/rules/#pyflakes-f
    "W",   # https://beta.ruff.rs/docs/rules/#warning-w
    "E",   # https://beta.ruff.rs/docs/rules/#error-e
    "I",   # https://beta.ruff.rs/docs/rules/#isort-i
    "N",   # https://beta.ruff.rs/docs/rules/#pep8-naming-n
    "ANN", # https://beta.ruff.rs/docs/rules/#flake8-annotations-ann
    "B",   # https://beta.ruff.rs/docs/rules/#flake8-bugbear-b
    "RUF", # https://beta.ruff.rs/docs/rules/#ruff-specific-rules-ruf
    "PT",  # https://beta.ruff.rs/docs/rules/#flake8-pytest-style-pt
    "D",
]
include = ["*.py"]
force-exclude = true
fixable = ["ALL"]
pydocstyle.convention = "numpy"

exclude = [".mypy_cache", ".ruff_cache", ".venv", "__pypackages__"]
ignore = [
    "ANN101", # https://beta.ruff.rs/docs/rules/#flake8-annotations-ann -- missing self type annotation
    "E501",   # Line-length is handled by black
    "N812",   # https://beta.ruff.rs/docs/rules/lowercase-imported-as-non-lowercase/
    "ANN401", # Ignore typing Any
    "D1",     # Don't complain about missing docstrings
]
1

There are 1 answers

0
tripleee On

Ruff does not currently support this. Quoting the Ruff FAQ:

Pylint implements many rules that Ruff does not, and vice versa. For example, Pylint does more type inference than Ruff (e.g., Pylint can validate the number of arguments in a function call). As such, Ruff is not a "pure" drop-in replacement for Pylint (and vice versa), as they enforce different sets of rules.

Despite these differences, many users have successfully switched from Pylint to Ruff, especially those using Ruff alongside a type checker, which can cover some of the functionality that Pylint provides.