-
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
[preview] FURB118 can be unsafe for methods #13829
Comments
Thanks for opening the issue. FURB118 has been something of a problematic rule for us in terms of the number of issues we've had regarding it :/ Here's a slightly smaller repro for the issue here, that makes it slightly clearer how the suggested change can break working code: >>> import operator
>>> class Spam:
... foo = lambda self, other: self == other
...
>>> class Eggs:
... foo = operator.eq
...
>>> Spam().foo(Spam())
False
>>> Eggs().foo(Eggs())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: eq expected 2 arguments, got 1 It seems like the The next question is what we can do about this. I think there are a few things we can do:
What I think we can't do, unfortunately, is avoid emitting the diagnostic in dynamic cases where you're monkey-patching a method onto a class, like the original situation you ran into in your |
I was under the impression it was a "safe" fix, but I reran it and it does only show up as an unsafe fix. (Aside: it would be nice if unsafe fixes were also indicated in the default printout, like All three improvements sound good. Probably no rush as it's not out of preview yet. |
This might possibly be addressed by #7352, which is definitely something we want to do at some point! |
If you run with
preview
set, then the FURB118 check makes an unsafe replacement, you can see me rolling back the change wntrblm/nox@a91dbe2 to make the tests pass, the difference in behavior can be shown with this MWE:The text was updated successfully, but these errors were encountered: