Improve handling of metaclasses in various linter rules#12579
Merged
AlexWaygood merged 1 commit intomainfrom Jul 30, 2024
Merged
Improve handling of metaclasses in various linter rules#12579AlexWaygood merged 1 commit intomainfrom
AlexWaygood merged 1 commit intomainfrom
Conversation
Contributor
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| ARG002 | 4 | 4 | 0 | 0 | 0 |
| ARG003 | 4 | 0 | 4 | 0 | 0 |
Linter (preview)
ℹ️ ecosystem check detected linter changes. (+4 -4 violations, +0 -0 fixes in 1 projects; 53 projects unchanged)
apache/airflow (+4 -4 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL
+ airflow/stats.py:46:24: ARG002 Unused method argument: `args` - airflow/stats.py:46:24: ARG003 Unused class method argument: `args` + airflow/stats.py:46:32: ARG002 Unused method argument: `kwargs` - airflow/stats.py:46:32: ARG003 Unused class method argument: `kwargs` + airflow/traces/tracer.py:259:24: ARG002 Unused method argument: `args` - airflow/traces/tracer.py:259:24: ARG003 Unused class method argument: `args` + airflow/traces/tracer.py:259:32: ARG002 Unused method argument: `kwargs` - airflow/traces/tracer.py:259:32: ARG003 Unused class method argument: `kwargs`
Changes by rule (2 rules affected)
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| ARG002 | 4 | 4 | 0 | 0 | 0 |
| ARG003 | 4 | 0 | 4 | 0 | 0 |
Member
Author
|
The ecosystem changes look good, in my opinion. I think those are all improvements in error messages. |
charliermarsh
approved these changes
Jul 30, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR does several interrelated things:
is_metaclassfunction out ofcrates/ruff_linter/src/rules/flake8_pyi/rules/non_self_return_type.rsand into theruff_python_semanticcrate. It's a generally useful function, and we were doing similar analysis elsewhere (but we were doing it incorrectly). It's better to centralize it in one place.classify()function inruff_python_semantic::analyze::function_typeso that it no longer reports that metaclass instance methods are classmethods. For ourpep8-namingrules, it makes sense to treat metaclass instance methods like classmethods, since metaclass instance methods usually useclsfor the name of the first parameter, like classmethods on non-metaclasses. However, theclassify()function is used by many other linter rules, not just ourpep8-namingrules. For those rules, it doesn't make sense for metaclass instance methods to be considered classmethods, since, well, they're not. An example is B019, which I've added a test for in this PR: I'm not sure it makes sense to treat instance methods on metaclasses any differently to instance methods on regular classes for that rule.ruff_python_semantic::analyze::function_type::classify()no longer considers instance methods on metaclasses to be classmethods, I adjusted thepep8-namingrules so that they now do their own check to see whether an instance method is a method on a metaclass, in order to determine what the name of the first parameter should be.FWIW, there were several buggy things in the check for metaclasses that
ruff_python_semantic::analyze::function_type::classify()was doing:map_callable()when it should have been usingmap_subscript()enum-module metaclasses that the stdlib providesTest Plan
cargo test -p ruff_linter