-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
False positive not-callable on type-annotated post-initialized class member #2562
Comments
Note that there is a workaround that works on both mypy and pylint (at least for now): before the class, declare a dummy method that returns the class type (specified as a string), and initialize the fields using the dummy method. |
- Work around 'not callable' false-positives by doing a better job of tricking the analysis into understanding class fields of the class type - Disable 'too-many-function-args' check around a line that's failing due to mypy not understanding overloads well enough Both false positives have been reported: - pylint-dev/pylint#2561 - pylint-dev/pylint#2562
pylint doesn't interpret type annotations at all, instead it relies on inference to figure out what the actual type of an object is. In this case, it might determine it's an union of |
@PCManticore, could we check condition of callable before checking to not-callable. For don't waite typing anotation in pylint. For pass of this example:
|
The discussion about taking into account type annotations is in #4813. I don't think it would be wise to add small workaround before we resolve that bigger issue. The maintenance cost is just too high. |
Steps to reproduce
Insert the following python code into a file
x.py
not-callable
enabledpylint --disable=all --enable=not-callable --score=no x.py
Current behavior
Pylint outputs an error
This is likely because pylint is looking at the temporary value
None
instead of trusting the type annotationtype: C
. (Note thatmypy
trusts the type annotation.)Expected behavior
Consider not outputing an error in this case, in order to make it possible to work around the fact that it is not possible to initialize class variables of the same type as the enclosing class until after the class is initialized, so it is necessary to have some sort of placeholder of an incorrect type.
pylint --version output
and separately
The text was updated successfully, but these errors were encountered: