-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Inconsistent behavior depending on cache -- dict.get returning Union of key and value types #6509
Comments
Confirmed on latest master. @ilevkivskyi probably knows what this is a duplicate of, though. :-) |
I think this is actually something new. (And it looks like a pure mystery.) |
@pdeblanc Is there an earlier mypy version where this was not broken? |
I'm not sure. |
I performed a
So I turned on
I double-checked that these are indeed the offending lines: diff --git a/mypy/checkexpr.py b/mypy/checkexpr.py
index 23ce56f..a5679f0 100644
--- a/mypy/checkexpr.py
+++ b/mypy/checkexpr.py
@@ -993,6 +993,13 @@ class ExpressionChecker(ExpressionVisitor[Type]):
e.name, original_type, e, is_lvalue, False, False,
self.named_type, self.not_ready_callback, self.msg,
original_type=original_type, chk=self.chk)
+ if isinstance(member_type, CallableType):
+ for v in member_type.variables:
+ v.id.meta_level = 0
+ if isinstance(member_type, Overloaded):
+ for it in member_type.items():
+ for v in it.variables:
+ v.id.meta_level = 0 // This line causes the bug in the OP.
if is_lvalue:
return member_type
else: On However, the purpose of the original commit was to fix this issue from Feb 4, 2017. Deleting In the PR thread of this commit, @JukkaL expressed concerns that sound relevant to me, though I have no idea what's going on (I've never used
He changed his mind about this concern and approved the PR, but it seems like he was right after all. I suppose that a fix will need to deal with the |
Wow, thanks for the extensive research! That helps a lot.
|
No problem! |
This is probably not directly related, but I noticed that these type definitions seem incorrect:
I think the |
No, we tried that, and it broke stuff. See python/typeshed#2817 |
What about |
You must be misreading something. The code restored in python/typeshed#2817 uses (essentially) |
Got it, perhaps I was looking at some older commit. |
This bug appears to have been fixed at some point. The latest version of mypy produces consistent results when running multiple times on the code sample. |
Python 3.7.2, mypy 0.670 (I also tried 70565cd, which was the most recent commit on master at the time of my testing).
File
foo.py
:The first time running
mypy foo.py
produces the expected output:Now running
mypy foo.py
a second time produces a spurious error:The text was updated successfully, but these errors were encountered: