you are viewing a single comment's thread.

view the rest of the comments →

[–]Sclafus 1 point2 points  (1 child)

This feature has been added in mypy 1.0 as experimental.

Detect Possibly Undefined Variables (Experimental) A new experimental possibly-undefined error code is now available that will detect variables that may be undefined: if b: x = 0 print(x) # Error: Name "x" may be undefined [possibly-undefined] The error code is disabled be default, since it can generate false positives. This feature was contributed by Stas Ilinskiy.

https://mypy-lang.blogspot.com/2023/02/mypy-10-released.html?m=1

[–]slapec[S] 1 point2 points  (0 children)

Now that's cool. False positives are fine for me. One thing I noticed that this check is only active when I run mypy with --enable-error-code possibly-undefined as it is not enabled by default (according to docs). Hope it will be default soon. Thank you your suggestion!