-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove rule A003 #7806
Comments
Yeah, it's kind of a confusing rule. It's not entirely useless -- it does make some sense when you consider cases like: class C:
@staticmethod
def list() -> None:
pass
@staticmethod
def repeat(value: int, times: int) -> list[int]:
return [value] * times In the latter definition, I don't know that renaming to A903 is that helpful, since it'd still be enabled via We could consider only flagging A003 the actual usage, i.e., when you do |
That sounds like a good idea ! But that example is not the best, since type hints can be just strings with a future import annotations.
DIdn't know that. |
@charliermarsh That is a very niche case that's probably better dealt with by having A003 exclusively detect the case where a function or static method name is shadowing a built-in. The problem now is the code path that detects A001 will warn about A003 if it's a class attribute assignment, A003 will warn again when it is a class attribute assignment, and A003 makes no distinction between instance/class methods which you have to access via a selector, and static methods, which do not have this requirement. P.S. I think there should be a rule that errors whenever a static method is introduced but I digress... |
@wyuenho - I don't believe that |
That makes sense, and it's a case of gforcada/flake8-builtins#75 (comment). Is there an easy way to only warn when there's a reference in the class scope call site? If not then I guess it's worth documenting some of the cases here and suggest to the user to ignore A003 as there are too many false negatives, and type checkers such as mypy and pyright can already catch some of them. |
I think we can feasibly change this rule to only flag cases in which you shadow a builtin, and then it gets referenced (like the |
PR up that should make this rule far more useful by only flagging actual shadowed reads (like in the example above) rather than the method definitions (which will almost always be fine): #9462 |
Hi.
Rule A003 (inherited from the flake8-builtins project) makes no sense.
Class scopes do not leak symbols to the global scope. They are their own isolated scopes.
E.g. this will trigger the warning
The warning is implemented here
https://github.com/astral-sh/ruff/blob/a1509dfc7c2b16f3762545fc802d49f5f03726e2/crates/ruff_linter/src/rules/flake8_builtins/rules/builtin_attribute_shadowing.rs
Issue on master branch.
Alternatively, rename it to A903 so it is an opinionated warning.
PS: there was a bug open in the original project but the owner is not taking any initiative gforcada/flake8-builtins#75
The text was updated successfully, but these errors were encountered: