8000 Fix #1855: Multiassign from Union (take 2) by elazarg · Pull Request #2219 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Fix #1855: Multiassign from Union (take 2) #2219

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
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c53a1c4
NewType+namedtuple: common method for typeinfo
elazarg Sep 3, 2016
7e043d0
handle union, add test
elazarg Sep 18, 2016
9a50d73
kill blank
elazarg Sep 18, 2016
5c4d86e
more tests
elazarg Sep 18, 2016
60cfbbb
handle binding
elazarg Sep 19, 2016
5e9e0f2
try to minimize visual difference
elazarg Sep 19, 2016
71f8475
(cont.)
elazarg Sep 19, 2016
42b6e73
add tests
elazarg Sep 21, 2016
0560bd8
no binder yet
elazarg Sep 23, 2016
da3a516
Support rebinding on multiassignment from union
elazarg Sep 27, 2016
ab60317
Merge remote-tracking branch 'upstream/master' into multiassign_union
elazarg Sep 27, 2016
6bb5519
more tests
elazarg Sep 27, 2016
3b4cd13
Merge remote-tracking branch 'upstream/master'
elazarg Oct 2, 2016
38651c4
handle union, add test
elazarg Sep 18, 2016
9000099
kill blank
elazarg Sep 18, 2016
f20f3d6
more tests
elazarg Sep 18, 2016
61be4e9
handle binding
elazarg Sep 19, 2016
9830cb4
try to minimize visual difference
elazarg Sep 19, 2016
59dc8b7
(cont.)
elazarg Sep 19, 2016
7f304e4
add tests
elazarg Sep 21, 2016
ff1ca80
no binder yet
elazarg Sep 23, 2016
168087e
Support rebinding on multiassignment from union
elazarg Sep 27, 2016
3f198cf
more tests
elazarg Sep 27, 2016
4fa059f
Rebase
elazarg Oct 5, 2016
ab35a4c
Merge
elazarg Oct 5, 2016
00f34ce
small merge fix
elazarg Oct 5, 2016
0cccb4b
Merge
elazarg Oct 7, 2016
a3ef3d5
what typeshed?
elazarg Oct 7, 2016
60c032f
Merge remote-tracking branch 'upstream/master' into multiassign_union2
elazarg Oct 11, 2016
21ac123
Merge remote-tracking branch 'upstream/master' into multiassign_union2
elazarg Oct 18, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
more tests
  • Loading branch information
elazarg committed Sep 27, 2016
commit 6bb5519f3493cebc209d3cea2997e5f143b39dd2
2 changes: 1 addition & 1 deletion mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@ def check_multi_assign_from_union(self, lvalues: List[Expression], rvalue: Expre
undefined_rvalue=True,
infer_lvalue_type=infer_lvalue_type)
for t, lv in zip(transposed, lvalues):
t.append(self.type_map[lv])
t.append(self.type_map.get(lv, AnyType()))
union_types = tuple(join_type_list(col) for col in transposed)
for expr, items in assignments.items():
types, declared_types = zip(*items)
Expand Down
67 changes: 63 additions & 4 deletions test-data/unit/check-unions.test
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,66 @@ reveal_type(obj) # E: Revealed type is 'builtins.int'

[builtins fixtures/list.pyi]

-- [case testUnionListInit]
-- from typing import Union, List
-- a = [] # type: Union[List[int], List[str]]
-- [builtins fixtures/list.pyi]
[case testUnionMultiassignAlreadyDeclared]
from typing import Union, Tuple

a = None # type: Union[Tuple[int, int], Tuple[int, float]]
a1 = None # type: object
a2 = None # type: int

(a1, a2) = a # E: Incompatible types in assignment (expression has type "float", variable has type "int")

b = None # type: Union[Tuple[float, int], Tuple[int, int]]
b1 = None # type: object
b2 = None # type: int

(b1, b2) = a # E: Incompatible types in assignment (expression has type "float", variable has type "int")

c = None # type: Union[Tuple[int, int], Tuple[int, int]]
c1 = None # type: object
c2 = None # type: int

(c1, c2) = c
reveal_type(c1) # E: Revealed type is 'builtins.int'
reveal_type(c2) # E: Revealed type is 'builtins.int'

d = None # type: Union[Tuple[int, int], Tuple[int, float]]
d1 = None # type: object

(d1, d2) = d
reveal_type(d1) # E: Revealed type is 'builtins.int'
reveal_type(d2) # E: Revealed type is 'builtins.float'

[case testUnionMultiassignIndexed]
from typing import Union, Tuple, List

class B:
x = None # type: object

x = None # type: List[int]
b = None # type: B

a = None # type: Union[Tuple[int, int], Tuple[int, object]]
(x[0], b.x) = a

# I don't know why is it incomplete type
reveal_type(x[0]) # E: Revealed type is 'builtins.int*'
reveal_type(b.x) # E: Revealed type is 'builtins.object'

[builtins fixtures/list.pyi]

[case testUnionMultiassignPacked]
from typing import Union, Tuple, List

a = None # type: Union[Tuple[int, int, int], Tuple[int, int, str]]
a1 = None # type: int
a2 = None # type: object
--FIX: allow proper rebinding of packed
xs = None # type: List[int]
(a1, *xs, a2) = a

reveal_type(a1) # E: Revealed type is 'builtins.int'
reveal_type(xs) # E: Revealed type is 'builtins.list[builtins.int]'
reveal_type(a2) # E: Revealed type is 'builtins.int'

[builtins fixtures/list.pyi]
1 change: 1 addition & 0 deletions test-data/unit/fixtures/list.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class list(Iterable[T], Generic[T]):
def __add__(self, x: list[T]) -> list[T]: pass
def __mul__(self, x: int) -> list[T]: pass
def __getitem__(self, x: int) -> T: pass
def __setitem__(self, x: int, v: T) -> None: pass
def append(self, x: T) -> None: pass
def extend(self, x: Iterable[T]) -> None: pass

Expand Down
0