-
Notifications
You must be signed in to change notification settings - Fork 133
Undefined variable: 'str' as part of correct type annotation #1732
Comments
Just to verify, does writing |
Yes, I should have added—everywhere else everything is fine |
Thanks @jakebailey . I just looked again to see if I could see any anomaly—I think maybe I found it: https://github.com/pydata/xarray/blob/b649846b9ceef0db8631e7148f5ee9415bdd4621/xarray/core/dataarray.py#L3117 So potentially mypy is ignoring that, but python-language-server isn't? |
Ah, that's probably it, in which case this may actually be a class scoping issue along with missing dataflow analysis to know that the assignment comes after. |
I think this issue is much broader as I'm getting a lot more false positives lately, where just editing a single character with valid python trips up the parser for the entire file. I reported it in the wrong place, though: microsoft/PTVS#4835. Even after a clean Languageserver install, this keeps happening. My colleague has the exact same laptop and extensions on vscode except for IntelliCode installed and doesn't have the issue so far, if that may be of any help! languageServer Python Extension VS Code |
0.4.71 is fairly old (as we haven't pushed to stable in a bit). Could you try out the beta build? https://github.com/microsoft/python-language-server/wiki/Versioning-and-download-channels |
Most probably addressed by #1798. Feel free to reopen if it is still an issue. |
FYI I do still get this. I rechecked since trying Pylance, though it occurs even if Pylance is disabled in favor of To repro, it's on this line: https://github.com/pydata/xarray/blob/v0.15.1/xarray/core/dataarray.py#L242 I can also provide logs if helpful Should I open a new issue? |
Type annotations do not follow code flow order when an annotation symbol is resolved. They support forward declarations. Here are two options for how to work around this in your code:
I realize that mypy may allow you to get away with redeclaring a built-in symbol at the end of the file, but Pylint/Pyright don't because of the lazy evaluation design that gives them their fast performance. I'll also point out that mypy will likely need to change their behavior for Python 3.9 because of this new language feature: Postponed Evaluation of Type Annotations. |
microsoft/pylance-release#19 (if you want the pylance discussion). |
Uh oh!
There was an error while loading. Please reload this page.
Environment data
Expected behaviour
No error message
Actual behaviour
Undefined variable: 'str'
as part of correct type annotation(other errors are unrelated)
Potentially related: #1453
Logs
https://gist.github.com/max-sixty/630b88f44038174dc46229edc51734b9
Reproducible from
dataarray.py
on xarray master, if anyone wants a full reproThank you!
The text was updated successfully, but these errors were encountered: