[ty] Detect invalid attribute overrides#24767
Conversation
Typing conformance results improved 🎉The percentage of diagnostics emitted that were expected errors increased from 87.94% to 87.96%. The percentage of expected errors that received a diagnostic increased from 83.36% to 83.55%. The number of fully passing files improved from 79/133 to 80/133. SummaryHow are test cases classified?Each test case represents one expected error annotation or a group of annotations sharing a tag. Counts are per test case, not per diagnostic — multiple diagnostics on the same line count as one. Required annotations (
Test file breakdown1 file altered
True positives added (2)2 diagnostics
|
Memory usage reportSummary
Significant changesClick to expand detailed breakdownsphinx
prefect
flake8
trio
|
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-attribute-override |
55 | 0 | 0 |
| Total | 55 | 0 | 0 |
Raw diff (55 changes)
archinstall (https://github.com/archlinux/archinstall)
+ archinstall/tui/ui/components.py:43:2 error[invalid-attribute-override] Invalid override of attribute `BINDINGS`: class variable cannot override instance variable `Screen.BINDINGS`
+ archinstall/tui/ui/components.py:369:2 error[invalid-attribute-override] Invalid override of attribute `BINDINGS`: class variable cannot override instance variable `SelectionList.BINDINGS`
dd-trace-py (https://github.com/DataDog/dd-trace-py)
+ ddtrace/contrib/_events/llm.py:40:5 error[invalid-attribute-override] Invalid override of attribute `span_type`: instance variable cannot override class variable `TracingEvent.span_type`
discord.py (https://github.com/Rapptz/discord.py)
+ discord/enums.py:113:9 error[invalid-attribute-override] Invalid override of attribute `__name__`: class variable cannot override instance variable `type.__name__`
django-stubs (https://github.com/typeddjango/django-stubs)
+ tests/assert_type/db/migrations/test_classvar.py:18:5 error[invalid-attribute-override] Invalid override of attribute `operations`: instance variable cannot override class variable `Migration.operations`
+ tests/assert_type/db/migrations/test_classvar.py:19:5 error[invalid-attribute-override] Invalid override of attribute `initial`: instance variable cannot override class variable `Migration.initial`
pip (https://github.com/pypa/pip)
+ src/pip/_vendor/urllib3/connection.py:107:5 error[invalid-attribute-override] Invalid override of attribute `default_port`: class variable cannot override instance variable `HTTPConnection.default_port`
prefect (https://github.com/PrefectHQ/prefect)
+ src/integrations/prefect-ray/prefect_ray/context.py:21:5 error[invalid-attribute-override] Invalid override of attribute `__var__`: instance variable cannot override class variable `ContextModel.__var__`
scipy-stubs (https://github.com/scipy/scipy-stubs)
+ scipy-stubs/stats/_resampling.pyi:75:5 error[invalid-attribute-override] Invalid override of attribute `__match_args__`: class variable cannot override instance variable `ResamplingMethod.__match_args__`
+ scipy-stubs/stats/_resampling.pyi:121:5 error[invalid-attribute-override] Invalid override of attribute `__match_args__`: class variable cannot override instance variable `ResamplingMethod.__match_args__`
sphinx (https://github.com/sphinx-doc/sphinx)
+ sphinx/directives/__init__.py:55:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/directives/__init__.py:360:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/directives/admonitions.py:30:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `BaseAdmonition.option_spec`
+ sphinx/directives/admonitions.py:31:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `BaseAdmonition.option_spec`
+ sphinx/domains/changeset.py:62:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/domains/index.py:71:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/ext/ifconfig.py:44:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/ext/todo.py:105:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/transforms/post_transforms/__init__.py:65:5 error[invalid-attribute-override] Invalid override of attribute `default_priority`: class variable cannot override instance variable `Transform.default_priority`
+ sphinx/directives/code.py:41:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/directives/code.py:108:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/directives/code.py:423:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/directives/other.py:194:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/directives/other.py:226:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/directives/other.py:242:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/directives/other.py:263:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/directives/other.py:283:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/directives/other.py:318:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/directives/patches.py:92:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/directives/patches.py:142:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/domains/c/__init__.py:421:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/domains/c/__init__.py:451:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/domains/c/__init__.py:480:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/domains/cpp/__init__.py:542:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/domains/cpp/__init__.py:573:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/domains/cpp/__init__.py:603:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/domains/javascript.py:335:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/domains/python/__init__.py:480:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/domains/python/__init__.py:548:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/domains/std/__init__.py:197:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/domains/std/__init__.py:340:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/domains/std/__init__.py:419:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/domains/std/__init__.py:599:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/ext/autosummary/__init__.py:202:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/ext/doctest.py:151:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/ext/doctest.py:157:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/ext/doctest.py:163:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/ext/doctest.py:174:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/ext/doctest.py:184:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/ext/graphviz.py:121:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/ext/graphviz.py:201:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/ext/inheritance_diagram.py:398:5 error[invalid-attribute-override] Invalid override of attribute `option_spec`: class variable cannot override instance variable `Directive.option_spec`
+ sphinx/transforms/__init__.py:368:5 error[invalid-attribute-override] Invalid override of attribute `smartquotes_action`: class variable cannot override instance variable `SmartQuotes.smartquotes_action`
+ sphinx/transforms/post_transforms/code.py:38:5 error[invalid-attribute-override] Invalid override of attribute `default_priority`: class variable cannot override instance variable `Transform.default_priority`
urllib3 (https://github.com/urllib3/urllib3)
+ src/urllib3/connection.py:107:5 error[invalid-attribute-override] Invalid override of attribute `default_port`: class variable cannot override instance variable `HTTPConnection.default_port`
Merging this PR will not alter performance
Comparing Footnotes
|
413dc92 to
d236787
Compare
|
The ecosystem changes are all true positives or cases that already have type ignores for other type-checkers. |
096ace5 to
2684664
Compare
b28ed78 to
e6842c3
Compare
AlexWaygood
left a comment
There was a problem hiding this comment.
We shouldn't use the invalid-method-override rule code for overrides of things that aren't methods. I deliberately gave that rule quite a specific name so that other kinds of overrides could have dedicated error codes with dedicated documentation pages, so it would be easy for users to find more explanation of why certain kinds of overrides are unsound
|
Aye aye boss |
a05fec7 to
1d8c3fe
Compare
Summary
We now detect Liskov violations when a parent-child pair have attributes with a differing
ClassVarstatus.In general, we interpret an attribute without a
ClassVarannotation as an instance attribute, with the exception of cases like the following, where we "allow" the child to "inherit" the annotation to adhere to the conformance suite:Closes astral-sh/ty#3093.