-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Allow assignments to multiple targets from union types #4067
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
Changes from 1 commit
b89fc28
13cd547
d550e4a
f4b57eb
edd70cc
9a68ae6
012be52
1a34540
036af84
a4b734b
950b8f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
from typing import Dict, List, Set, Iterator, Union, Optional, Tuple, DefaultDict, cast | ||
from typing import Dict, List, Set, Iterator, Union, Optional, Tuple, cast | ||
from contextlib import contextmanager | ||
from collections import defaultdict | ||
|
||
MYPY = False | ||
if MYPY: | ||
from typing import DefaultDict | ||
|
||
from mypy.types import Type, AnyType, PartialType, UnionType, TypeOfAny | ||
from mypy.subtypes import is_subtype | ||
from mypy.join import join_simple | ||
|
@@ -38,7 +42,8 @@ def __init__(self) -> None: | |
self.unreachable = False | ||
|
||
|
||
Assigns = DefaultDict[Expression, List[Tuple[Type, Optional[Type]]]] | ||
if MYPY: | ||
Assigns = DefaultDict[Expression, List[Tuple[Type, Optional[Type]]]] | ||
|
||
|
||
class ConditionalTypeBinder: | ||
|
@@ -216,7 +221,7 @@ def pop_frame(self, can_skip: bool, fall_through: int) -> Frame: | |
return result | ||
|
||
@contextmanager | ||
def accumulate_type_assignments(self) -> Iterator[Assigns]: | ||
def accumulate_type_assignments(self) -> 'Iterator[Assigns]': | ||
self.type_assignments = defaultdict(list) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add docstring. Also mention that this is used for multi-assignment from union (and why this is needed there). |
||
yield self.type_assignments | ||
self.type_assignments = None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about things like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you are totally right. Will push a commit in a second. Also testing this uncovered another flaw in my implementation: I need to iterate over nested lvalues in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add comment that explains what this is used for.