[ruff] Add RUF074 incorrect-decorator-order #23461
[ruff] Add RUF074 incorrect-decorator-order #23461anishgirianish wants to merge 10 commits intoastral-sh:mainfrom
RUF074 incorrect-decorator-order #23461Conversation
incorrect-decorator-order (RUF071)RUF071 incorrect-decorator-order
|
|
Could you check the ecosystem results? |
sure checking now thanks |
ntBre
left a comment
There was a problem hiding this comment.
Thanks, this looks reasonable to me overall (although I still need to go through all the test cases). I mainly had a question about the multi-decorator case and a nit about Display.
crates/ruff_linter/src/rules/ruff/rules/incorrect_decorator_order.rs
Outdated
Show resolved
Hide resolved
crates/ruff_linter/src/rules/ruff/rules/incorrect_decorator_order.rs
Outdated
Show resolved
Hide resolved
ntBre
left a comment
There was a problem hiding this comment.
Thanks! Just a couple more questions about @property.setter and possible references for the chosen pairs.
7b99afd to
ced38ec
Compare
Bump IncorrectDecoratorOrder from RUF071 to RUF072 since RUF071 was taken by OsPathCommonprefix upstream.
ced38ec to
41d5164
Compare
RUF071 incorrect-decorator-order RUF072 incorrect-decorator-order
…corator-order # Conflicts: # crates/ruff_linter/resources/test/fixtures/ruff/RUF072.py # crates/ruff_linter/src/codes.rs # crates/ruff_linter/src/rules/ruff/mod.rs # crates/ruff_linter/src/rules/ruff/snapshots/ruff_linter__rules__ruff__tests__preview__RUF072_RUF072.py.snap # ruff.schema.json
RUF072 incorrect-decorator-order RUF074 incorrect-decorator-order
Summary
Implements detection of incorrect decorator ordering on functions and methods (RUF071).
Decorators are applied bottom-up, so certain stdlib decorator combinations cause runtime errors or silent wrong behavior when placed in the wrong order. For example,
@abstractmethodabove@propertyresults inAttributeError: __isabstractmethod__.Detects known-bad pairs involving:
abc.abstractmethod(+ deprecatedabstractclassmethod,abstractstaticmethod,abstractproperty)builtins.property,builtins.classmethod,builtins.staticmethodcontextlib.contextmanager,contextlib.asynccontextmanagerfunctools.cache,functools.cached_property,functools.lru_cacheTest Plan
cargo nextest run -p ruff_linter -E 'test(preview_rules::rule_incorrectdecoratororder)'Fixture covers:
abc.abstractmethod,functools.lru_cache)abstractproperty,abstractclassmethod,abstractstaticmethod)@lru_cache(),@lru_cache(maxsize=128))Closes #6697