astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
31.44k stars 1.05k forks source link

Ruff fails to detect obvious AttributeErrors #10833

Open edreamleo opened 5 months ago

edreamleo commented 5 months ago

Consider the following file, say test.py:

class Test:
    __slots__ = ('good',)

def main():
    t = Test()
    print(t.bad)  # Obvious AttributeError

main()

Running python -m ruff check test.py fails to detect any error, with or without the __slots__ statement.

Pylint used to detect such errors, at least in some cases, but no longer does. Correction: pylint issues ano-member warning as expected.

Are there any plans to add such checks to Ruff?

Context

Python 3.12.0, PyQt version 6.6.3
Windows 11 AMD64 (build 10.0.22631) SP0
>ruff --version
ruff 0.3.5

pyproject.toml

[tool.ruff]
line-length = 120

ruff.toml

[lint]
ignore = [
    "E402", # Module level import not at top of file
    "E701", # Multiple statements on one line (colon)
    "E702", # Multiple statements on one line (semicolon)
    "E711", # Comparison to `None` should be `cond is None`
    "E731", # Do not assign a `lambda` expression, use a `def`
    "E741", # Ambiguous variable name: `l`. Bad style, but only occurs in minor plugins.

    "F401", # `xxx` imported but unused. Pyflakes checks this.
    "F841", # Local variable `xxx` is assigned to but never used. Pyflakes checks this.
]

exclude = [
    # Exclude entire folders...
    "leo/external/*.py",
    "leo/external/npyscreen/*.py",
    "leo/external/npyscreen/compatibility_code/*.py",
    "leo/plugins/obsolete/*.py",
    "leo/plugins/leo_babel/babel*.py",
    "leo/plugins/leo_babel/tests/*.py",
    "leo/scripts/*.py",
    # Exclude unusual plugins.
    "leo/doc/sphinx-docs/conf.py",
    "leo/plugins/md_docer.py",
    "leo/plugins/qt_main.py",  # Generated automatically.
    "leo/plugins/test/failed_import.py",  # Contains unused import of 'xyzzy'.
    "leo/plugins/pygeotag/pygeotag.py",  # Contains strange errors.
    "leo/test/scriptFile.py",  # Generated by *user* scripts.
    "leo/unittests/py3_test_grammar.py",  # Contains many errors on purpose.
]

Edward

MichaReiser commented 5 months ago

Thanks for the detailed write up.

Yes, we do have plans to add checks like this in the future when we work on adding more static analysis (type checking like) capabilities to Ruff. This should unlock a whole new set of rules that Ruff can support :)

edreamleo commented 5 months ago

@MichaReiser

Thanks for the detailed write up.

You're welcome! Thanks for your quick response.

Yes, we do have plans to add checks like this in the future when we work on adding more static analysis (type checking like) capabilities to Ruff. This should unlock a whole new set of rules that Ruff can support :)

“O frabjous day! Callooh! Callay!” He chortled in his joy.

Edward