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

x = x or y with x undeclared gives no error #937

Open
jhance opened this issue Oct 15, 2015 · 2 comments
Open

x = x or y with x undeclared gives no error #937

jhance opened this issue Oct 15, 2015 · 2 comments
Labels
bug mypy got something wrong priority-1-normal topic-runtime-semantics mypy doesn't model runtime semantics correctly topic-variable-scope

Comments

@jhance
Copy link
Collaborator

jhance commented Oct 15, 2015

I think it should, because python considers such recursive definitions to be an error.

@JukkaL JukkaL added the bug mypy got something wrong label Oct 16, 2015
@JukkaL
Copy link
Collaborator

JukkaL commented Oct 16, 2015

This should definitely be an error.

@jhance
Copy link
Collaborator Author

jhance commented Oct 17, 2015

I had a bit of trouble replicating. Easiest way was a type annotation:

x = x or 0 # type: int

Another way is to just do it in function scope (no type annotation needed).

Seems like we treat this as x already being defined (since we know its type). A bit of introspection reveals that lvalue.is_def = False so the fault is probably within the semantic analyzer. However, this only happens in global scope, I'm finding that in function scope that is_def = True (and in this scenario, I have no idea how its not encountering an error).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong priority-1-normal topic-runtime-semantics mypy doesn't model runtime semantics correctly topic-variable-scope
Projects
None yet
Development

No branches or pull requests

4 participants