Skip to content
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

pylance doesn't recognize default variable __annotations__ #1161

Closed
notatallshaw opened this issue Apr 15, 2021 · 4 comments
Closed

pylance doesn't recognize default variable __annotations__ #1161

notatallshaw opened this issue Apr 15, 2021 · 4 comments
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@notatallshaw
Copy link

Environment data

  • Language Server version: Pylance 2021.4.1
  • OS and version: Windows 10
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.8.8

Expected behaviour

pylance should not give an error when using the __annotations__ dictionary in your code

Actual behaviour

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
}

Code Snippet / Additional information

print(__annotations__)

p.s. Sorry if this has already been reported I couldn't find it anywhere.

@erictraut
Copy link
Contributor

Thanks for the bug report. This will be fixed in the next release of pylance.

@erictraut erictraut added bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version and removed triage labels Apr 15, 2021
@notatallshaw
Copy link
Author

notatallshaw commented Apr 15, 2021

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: python/mypy#3075

@jakebailey
Copy link
Member

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

@notatallshaw
Copy link
Author

Confirmed, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

3 participants