-
-
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
undefined-variable on correct return type hints #3461
Comments
The "right" code isn't really correct. You'd need to forward the reference: |
I could run it with If that's really not good enough, the message level should be |
any update? |
You're right, my bad, mixed something up. It appears that pylint cannot handle type hints very well. |
Thanks for the report. This is definitely a bug, and it's unrelated to type hints. It's caused by For instance, if the code would be written like this, the error would not be emitted:
|
It seems to have been fixed in 2.5. Is it right? |
No, this has not been fixed yet. I've just tried to convert some parts of our code base with https://github.com/ilevkivskyi/com2ann and stumbled over quite a few places which had to be fixed by hand (adding quotes) because pylint doesn't get the scoping right. It is quite common that signatures of methods in a class Foo involve, well, Foo, so this pylint bug is really annoying in a large code base... |
One more point: pylint should somehow treat typing.TYPE_CHECKING like mypy does, otherwise the scoping is screwed up for another reason. |
@craynic Yes, the false positive for (If converting a large code base, Pylint may encounter other type hint and scoping related issues--some of which have bug reports--but I think the specific case in this issue is now addressed) |
) Fix scoping for function annotations, decorators and base classes Closes #1082, #3434, #3461 Reduce number of branches in variables checker Co-authored-by: Andrew Simmons <[email protected]>
Fixed in #3713 |
Steps to reproduce
code:
Got an error in running:
Current behavior
tmp.py:7:22: E0602: Undefined variable 'Result1' (undefined-variable)
Expected behavior
tmp.py:14:22: E0602: Undefined variable 'self' (undefined-variable)
pylint --version output
pylint 2.4.4
astroid 2.3.3
Python 3.8.2 (default, Feb 26 2020, 22:21:03)
The text was updated successfully, but these errors were encountered: