-
-
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
false negative: used-before-assignment w/ TYPE_CHECKING guard #8893
Comments
Kinda feels like the obverse of #8111 |
This was partially fixed on the main brach by #8198 (I think). if TYPE_CHECKING:
import datetime
def f():
return datetime.datetime.now() # flagged -- good
def g() -> datetime.datetime:
return datetime.datetime.now() # not flagged -- bad Perhaps it's a strange case, but there is also a false negative for classes defined in the if TYPE_CHECKING:
class X:
pass
def f():
return X() # not flagged -- bad
def g() -> X:
return X() # not flagged -- bad |
Yeah I think that’s interesting that only the first issue is flagged. In my worst case, only the first datetime usage is flagged as well. |
I observe a quite similar issue which was introduced in Steps to reproduce: @dataclass
class Foo:
my_list: list[Bar] which fails with |
@hofbi Does that file include |
@DanielNoord No, no |
#9587 was a duplicate for |
Shooting from the hip, I bet in |
However, #8431 added a different approach for this, so it's worth examining whether we should tweak it or drop it. It probably shouldn't be assuming that we can have one approach to type-checking imports per scope. |
Bug description
Consider the following code:
Pylint can and does flag the
z = ...
line as used-before-assignment. However, if we usedatetime
somewhere as a type annotation, say inpylint returns "10/10, would lint again". pylint should flag the
used-before-assignment
errors here, since this code will blow up at runtime when called.Command used
Pylint output
Expected behavior
consistent
used-before-assignment
lints.Pylint version
OS / Environment
Debian
The text was updated successfully, but these errors were encountered: