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

Typechecker doesn't see variables defined in class when typechecking default values for method args #307

Closed
gvanrossum opened this issue Jul 19, 2014 · 1 comment
Labels
bug mypy got something wrong

Comments

@gvanrossum
Copy link
Member

I have a class that defines some constants and uses those constants as defaults for some method arguments. This is fine in Python, but mypy complains that the constant isn't defined. Example:

bash-3.2$ cat /tmp/x.py
import typing

class C:
    DEFAULT_LEVEL = 1
    def set_level(self, level: int = DEFAULT_LEVEL) -> int:
        return level
bash-3.2$ PYTHONPATH=lib-typing/3.2/ python3 /tmp/x.py
bash-3.2$ PYTHONPATH=. python3 scripts/mypy /tmp/x.py
/tmp/x.py: In function "set_level":
/tmp/x.py, line 5: Name 'DEFAULT_LEVEL' is not defined
bash-3.2$ 
@JukkaL
Copy link
Collaborator

JukkaL commented Jul 23, 2014

Thanks for reporting this! The scoping of method argument defaults is clearly broken.

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

No branches or pull requests

2 participants