Language Server version: Pylance 2021.4.1
pylance should not give an error when using the __annotations__ dictionary in your code
pylance gives the error:
{
"resource": "****",
"owner": "_generated_diagnostic_collection_name_#1",
"code": {
"value": "reportUndefinedVariable",
"target": {
"$mid": 1,
"external": "https://github.com/microsoft/pylance-release/blob/main/DIAGNOSTIC_SEVERITY_RULES.md#diagnostic-severity-rules",
"path": "/microsoft/pylance-release/blob/main/DIAGNOSTIC_SEVERITY_RULES.md",
"scheme": "https",
"authority": "github.com",
"fragment": "diagnostic-severity-rules"
}
},
"severity": 8,
"message": "\"__annotations__\" is not defined",
"source": "Pylance",
"startLineNumber": 1,
"startColumn": 7,
"endLineNumber": 1,
"endColumn": 22
}
print(__annotations__)
p.s. Sorry if this has already been reported I couldn't find it anywhere.
Thanks for the bug report. This will be fixed in the next release of pylance.
Thanks for your fast response and fix! It was clearly not urgent as seemingly very few other users have noticed. I'm only noticing it because I am playing around with the differences caused by the current implementation of annotations, PEP 563s implementation, and PEP 649s implementation.
It seems like it was reported to mypy before but closed perhaps by accident when it was confused with an issue to do with Named Tuples: https://github.com/python/mypy/issues/3075
This issue has been fixed in version 2021.4.2, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202142-21-april-2021
Confirmed, thanks!