Skip to content

Annotation comment not working inside a function #2215

Closed
@roganov

Description

@roganov
from typing import Dict

xs = {}  # type: Dict[str, str]
reveal_type(xs)

def foo():
    xs = {}  # type: Dict[str, str]
    reveal_type(xs)
$ mypy mypytest.py
mypytest.py:4: error: Revealed type is 'builtins.dict[builtins.str, builtins.str]'
mypytest.py: note: In function "foo":
mypytest.py:8: error: Revealed type is 'Any'

Expected result
MyPy should reveal builtins.dict[builtins.str, builtins.str] in both cases

Actual result
MyPy correctly reveals type on module-level, but reveals Any inside the function

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions