ruff
ae2cf91a - [red-knot] Decorators and properties (#17017)

Commit
277 days ago
[red-knot] Decorators and properties (#17017) ## Summary Add support for decorators on function as well as support for properties by adding special handling for `@property` and `@<name of property>.setter`/`.getter` decorators. closes https://github.com/astral-sh/ruff/issues/16987 ## Ecosystem results - :heavy_check_mark: A lot of false positives are fixed by our new understanding of properties - :red_circle: A bunch of new false positives (typically `possibly-unbound-attribute` or `invalid-argument-type`) occur because we currently do not perform type narrowing on attributes. And with the new understanding of properties, this becomes even more relevant. In many cases, the narrowing occurs through an assertion, so this is also something that we need to implement to get rid of these false positives. - :red_circle: A few new false positives occur because we do not understand generics, and therefore some calls to custom setters fail. - :red_circle: Similarly, some false positives occur because we do not understand protocols yet. - :heavy_check_mark: Seems like a true positive to me. [The setter](https://github.com/pypa/packaging/blob/e624d8edfaa28865de7b5a7da8bd59fd410e5331/src/packaging/specifiers.py#L752-L754) only accepts `bools`, but `None` is assigned in [this line](https://github.com/pypa/packaging/blob/e624d8edfaa28865de7b5a7da8bd59fd410e5331/tests/test_specifiers.py#L688). ``` + error[lint:invalid-assignment] /tmp/mypy_primer/projects/packaging/tests/test_specifiers.py:688:9: Invalid assignment to data descriptor attribute `prereleases` on type `SpecifierSet` with custom `__set__` method ``` - :heavy_check_mark: This is arguable also a true positive. The setter [here](https://github.com/Textualize/rich/blob/0c6c75644f80530de219dae3e94f0aeb999f9b4c/rich/table.py#L359-L363) returns `Table`, but typeshed wants [setters to return `None`](https://github.com/python/typeshed/blob/bf8d2a99126dcb155692c0ba56c4866fcd618393/stdlib/builtins.pyi#L1298). ``` + error[lint:invalid-argument-type] /tmp/mypy_primer/projects/rich/rich/table.py:359:5: Object of type `Literal[padding]` cannot be assigned to parameter 2 (`fset`) of bound method `setter`; expected type `(Any, Any, /) -> None` ``` ## Follow ups - Fix the `@no_type_check` regression - Implement class decorators ## Test Plan New Markdown test suites for decorators and properties.
Author
Parents
Loading