-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Generating error if callable object is formatted as a string? #5213
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
Comments
I would prefeer option 4 because because seems more suited to a custom plugin for pylint. |
Pylint can't generate this error reliably since it doesn't do type inference. If mypy had a public plugin API, we'd have another option:
Finally, if we'd have finer-grained control of which errors to generate (#3806), it would be easier to justify enabling additional checks by default, since there would be a simple way to disable them. |
TBH, I have never had this problem. However, I several times had a similar, but harder to diagnose problem: |
Funnily enough, I've never had this problem. There is an existing issue for this: #1749 |
Now that we have error codes, this can be a simple follow-up for #7418 |
We still don't have a general way of enabling/disabling specific error codes. When that is supported, this could be just an optional check that can be enabled. |
Pretty frequently I have errors where I forget to call a method and accidentally pass a method object to
%
orstr.format
. Mypy doesn't complain since it's possible to convert a callable object to a string, though usually that's not what I want.Example:
This occasionally happens during refactoring as well, when I replace an instance variable with a method.
Here are a few things we could do about this:
repr(x.some_method)
to silence the error (# type: ignore
or a cast toobject
would also work).Option 2 seems too specialized -- this doesn't seem important enough to add a strictness flag. Personally I prefer the more opinionated option 1. We could add a hint about how to silence the error in case the code happens to be correct.
The text was updated successfully, but these errors were encountered: