-
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
extend-immutable-calls doesn't work on Python scripts (as opposed to modules) #10960
Comments
Hmm yeah... We need some way to identify |
|
(Updated the OP to note that I also tried with
I tried Since ruff interprets module paths statically, I think the best thing to do in this case would be to check that |
That seems reasonable to me. |
## Summary If the user is analyzing a script (i.e., we have no module path), it seems reasonable to use the script name when trying to identify paths to objects defined _within_ the script. Closes #10960. ## Test Plan Ran: ```shell check --isolated --select=B008 \ --config 'lint.flake8-bugbear.extend-immutable-calls=["test.A"]' \ test.py ``` On: ```python class A: pass def f(a=A()): pass ```
Keywords: extend-immutable-calls, B008, script, module,
__main__
Ruff version: 0.3.7
Working MWE
In a directory containing just the file
test.py
:checking with:
ruff check --isolated --select=B008 \ --config 'lint.flake8-bugbear.extend-immutable-calls=["other_module.A"]' \ test.py
yields no errors.
Buggy MWE
If I declare
A
in the script instead of importing it:now ruff will find a B008 error in the
def
line, no matter what I configure inextend-immutable-calls
. I triedA
,test.A
,__main__.A
, and evenbuiltins.A
and__builtins__.A
. Nothing makes it recognizeA()
as an immutable call.The text was updated successfully, but these errors were encountered: