Skip to content

Annotation comment not working inside a function #2215

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

Closed
roganov opened this issue Oct 4, 2016 · 1 comment
Closed

Annotation comment not working inside a function #2215

roganov opened this issue Oct 4, 2016 · 1 comment

Comments

@roganov
Copy link

roganov commented Oct 4, 2016

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

@gvanrossum
Copy link
Member

Mypy ignores the body of a function that has no annotations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants