-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
mypy loses type of optional Tuple variable after setting default in runtime #5393
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
Comments
As a workaround, can you use List instead of list? Does that make things
better? If not, what if you give it an explicit item type, e.g. List[int]?
|
changing list -> List[int] doesn't fix anything, I've found this problem with a custom type and a custom class as tuple elements, code above is simplified case
|
OK, looks like no union simplification is happening in this case. I'm declaring it a bug. Thanks for reporting! |
Problem with Union simplification seems to be caused by different One element has Following quick patch fixes this particular bug. diff --git a/mypy/types.py b/mypy/types.py
index f9d5d3c2..371ba427 100644
--- a/mypy/types.py
+++ b/mypy/types.py
@@ -1097,12 +1097,12 @@ class TupleType(Type):
return visitor.visit_tuple_type(self)
def __hash__(self) -> int:
- return hash((tuple(self.items), self.fallback))
+ return hash((tuple(self.items)))
def __eq__(self, other: object) -> bool:
if not isinstance(other, TupleType):
return NotImplemented
- return self.items == other.items and self.fallback == other.fallback
+ return self.items == other.items
def serialize(self) -> JsonDict:
return {'.class': 'TupleType', |
Do all the tests pass? Do you want to add a new test and turn that into a
PR?
|
With this patch some tests fail, but I'll try to make it into a proper PR. |
This hides the problem, fallback contains some actual info about tuples (e.g. for named tuples), so we should figure out why fallbacks are different instead of just ignoring them. |
The issue is now fixed, likely by #6442 |
Please provide more information to help us understand the issue:
reporting a bug
or a mock-up repro if the source is private. We would appreciate
if you try to simplify your case to a minimal repro.
mypy loses actual type of object
no errors in code above
Do you see the same issue after installing mypy from Git master?
fresh mypy from git master
none
The text was updated successfully, but these errors were encountered: