pylint
pylint copied to clipboard
Spurious 'undefined-variable' warning with postponed annotations enabled
Bug description
Hello,
The following raise an unexpected warning.
from __future__ import annotations
class A:
class B:
pass
class C:
b: B # undefined-variable
In Python 3.9, Pylint should not raise the undefined-variable
warning on B
if __future__.annotations
has been imported.
Have a good day !
Configuration
No response
Command used
no specific parameters
Pylint output
E0602: Undefined variable 'B' (undefined-variable)
Expected behavior
No warning
Pylint version
pylint 2.16.0
astroid 2.14.1
Python 3.9.2 (default, Feb 28 2021, 17:03:44)
OS / Environment
Debian bullseye 64bit
Additional dependencies
No response
@Pierre-Sassoulas were you able to reproduce? I tried with Python 3.9.2 and same pylint & astroid versions reported and could not.
Right sorry, I cannot reproduce on pylint main branch, could you upgrade to 2.17.0 @SamyCookie ?
I have reproduced the issue with up to date PyLint version
pylint 2.17.0
astroid 2.15.0
Python 3.9.2 (default, Feb 28 2021, 17:03:44)
[GCC 10.2.1 20210110]
************* Module foo
foo.py:6:11: E0602: Undefined variable 'B' (undefined-variable)
--------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 10.00/10, -0.00)
*** Error code 18
Stop.
Maybe you have forgotten to remove the disable
comment I had put in my example ?
I've also reproduced this issue with the following environment:
pylint 3.0.2
astroid 3.0.1
Python 3.9.2 (default, Feb 28 2021, 17:03:44)
[GCC 10.2.1 20210110]
I can provide the actual example case if needed, but the issue seems fairly clear. I'm using the same from __future__ import annotations
import, and getting the same undefined-variable
message.
(as a side note, I have access to an environment with up to Python 3.11 installed; if desired, I can test the same scenario on that environment and report back. Not sure if that would actually be helpful, though.)
Edit: this got marked as spam for some reason? Not sure why. I promise I'm a person.
I've also reproduced this issue with the following environment:
pylint 3.0.2 astroid 3.0.1 Python 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110]
I can provide the actual example case if needed, but the issue seems fairly clear. I'm using the same
from __future__ import annotations
import, and getting the sameundefined-variable
message.(as a side note, I have access to an environment with up to Python 3.11 installed; if desired, I can test the same scenario on that environment and report back. Not sure if that would actually be helpful, though.)
I also encountered the same issue pylint: 3.0.3 astroid 3.0.2 python 3.11
I've also reproduced this issue with the following environment:
pylint 3.0.2 astroid 3.0.1 Python 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110]
I can provide the actual example case if needed, but the issue seems fairly clear. I'm using the same
from __future__ import annotations
import, and getting the sameundefined-variable
message. (as a side note, I have access to an environment with up to Python 3.11 installed; if desired, I can test the same scenario on that environment and report back. Not sure if that would actually be helpful, though.)I also encountered the same issue pylint: 3.0.3 astroid 3.0.2 python 3.11
I find my case is because of the type is changed from "List" to "list".