Pylance-release: pylance doesn't recognize default variable __annotations__

Created on 15 Apr 2021  路  4Comments  路  Source: microsoft/pylance-release

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.

    bug fixed in next version

    All 4 comments

    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!

    Was this page helpful?
    0 / 5 - 0 ratings

    Related issues

    yankyhoffman picture yankyhoffman  路  5Comments

    savannahostrowski picture savannahostrowski  路  4Comments

    flaree picture flaree  路  4Comments

    munael picture munael  路  5Comments

    albireox picture albireox  路  5Comments