class ConditionalTypeBinder: (source)
Keep track of conditional types of variables.
NB: Variables are tracked by literal expression, so it is possible to confuse the binder; for example,
``` class A:
a = None # type: Union[int, str]
x = A() lst = [x] reveal_type(x.a) # Union[int, str] x.a = 1 reveal_type(x.a) # int reveal_type(lst[0].a) # Union[int, str] lst[0].a = 'a' reveal_type(x.a) # int reveal_type(lst[0].a) # str ```
Method | __init__ |
Undocumented |
Method | accumulate_type_assignments |
Push a new map to collect assigned types in multiassign from union. |
Method | allow_jump |
Undocumented |
Method | assign_type |
Undocumented |
Method | cleanse |
Remove all references to a Node from the binder. |
Method | frame_context |
Return a context manager that pushes/pops frames on enter/exit. |
Method | get |
Undocumented |
Method | handle_break |
Undocumented |
Method | handle_continue |
Undocumented |
Method | invalidate_dependencies |
Invalidate knowledge of types that include expr, but not expr itself. |
Method | is_unreachable |
Undocumented |
Method | is_unreachable_warning_suppressed |
Undocumented |
Method | most_recent_enclosing_type |
Undocumented |
Method | pop_frame |
Pop a frame and return it. |
Method | push_frame |
Push a new frame into the binder. |
Method | put |
Undocumented |
Method | suppress_unreachable_warnings |
Undocumented |
Method | top_frame_context |
A variant of frame_context for use at the top level of a namespace (module, function, or class). |
Method | unreachable |
Undocumented |
Method | update_from_options |
Update the frame to reflect that each key will be updated as in one of the frames. Return whether any item changes. |
Instance Variable | break_frames |
Undocumented |
Instance Variable | continue_frames |
Undocumented |
Instance Variable | declarations |
Undocumented |
Instance Variable | dependencies |
Undocumented |
Instance Variable | frames |
Undocumented |
Instance Variable | last_pop_changed |
Undocumented |
Instance Variable | next_id |
Undocumented |
Instance Variable | options_on_return |
Undocumented |
Instance Variable | try_frames |
Undocumented |
Instance Variable | type_assignments |
Undocumented |
Method | _add_dependencies |
Undocumented |
Method | _cleanse_key |
Remove all references to a key from the binder. |
Method | _get |
Undocumented |
Method | _get_id |
Undocumented |
Method | _put |
Undocumented |
Push a new map to collect assigned types in multiassign from union.
If this map is not None, actual binding is deferred until all items in the union are processed (a union of collected items is later bound manually by the caller).
Returns | |
Iterator[ | Undocumented |
Undocumented
Parameters | |
expr:Expression | Undocumented |
type:Type | Undocumented |
declared_type:Optional[ | Undocumented |
restrict_any:bool | Undocumented |
Return a context manager that pushes/pops frames on enter/exit.
If can_skip is True, control flow is allowed to bypass the newly-created frame.
If fall_through > 0, then it will allow control flow that
falls off the end of the frame to escape to its ancestor
fall_through
levels higher. Otherwise control flow ends
at the end of the frame.
If break_frame > 0, then 'break' statements within this frame will jump out to the frame break_frame levels higher than the frame created by this call to frame_context. Similarly for continue_frame and 'continue' statements.
If try_frame is true, then execution is allowed to jump at any point within the newly created frame (or its descendants) to its parent (i.e., to the frame that was on top before this call to frame_context).
After the context manager exits, self.last_pop_changed indicates whether any types changed in the newly-topmost frame as a result of popping this frame.
Parameters | |
can_skip:bool | Undocumented |
fall_through:int | Undocumented |
break_frame:int | Undocumented |
continue_frame:int | Undocumented |
conditional_frame:bool | Undocumented |
try_frame:bool | Undocumented |
Returns | |
Iterator[ | Undocumented |
Invalidate knowledge of types that include expr, but not expr itself.
For example, when expr is foo.bar, invalidate foo.bar.baz.
It is overly conservative: it invalidates globally, including in code paths unreachable from here.
Parameters | |
expr:BindableExpression | Undocumented |
Undocumented
Parameters | |
expr:BindableExpression | Undocumented |
type:Type | Undocumented |
Returns | |
Optional[ | Undocumented |
Pop a frame and return it.
See frame_context() for documentation of fall_through.
Parameters | |
can_skip:bool | Undocumented |
fall_through:int | Undocumented |
Returns | |
Frame | Undocumented |
Parameters | |
conditional_frame:bool | Undocumented |
Returns | |
Frame | Undocumented |
Returns | |
Iterator[ | Undocumented |
Update the frame to reflect that each key will be updated as in one of the frames. Return whether any item changes.
If a key is declared as AnyType, only update it if all the options are the same.
Parameters | |
frames:List[ | Undocumented |
Returns | |
bool | Undocumented |