class documentation

class ConditionalTypeBinder: (source)

View In Hierarchy

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
def __init__(self): (source)

Undocumented

@contextmanager
def accumulate_type_assignments(self) -> Iterator[Assigns]: (source)

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).

def allow_jump(self, index: int): (source)

Undocumented

def assign_type(self, expr: Expression, type: Type, declared_type: Type|None, restrict_any: bool = False): (source)

Undocumented

def cleanse(self, expr: Expression): (source)

Remove all references to a Node from the binder.

@contextmanager
def frame_context(self, *, can_skip: bool, fall_through: int = 1, break_frame: int = 0, continue_frame: int = 0, conditional_frame: bool = False, try_frame: bool = False) -> Iterator[Frame]: (source)

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.

def get(self, expr: Expression) -> Type|None: (source)

Undocumented

def handle_break(self): (source)

Undocumented

def handle_continue(self): (source)

Undocumented

def invalidate_dependencies(self, expr: BindableExpression): (source)

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.

def is_unreachable(self) -> bool: (source)

Undocumented

def is_unreachable_warning_suppressed(self) -> bool: (source)

Undocumented

def most_recent_enclosing_type(self, expr: BindableExpression, type: Type) -> Type|None: (source)

Undocumented

def pop_frame(self, can_skip: bool, fall_through: int) -> Frame: (source)

Pop a frame and return it. See frame_context() for documentation of fall_through.

def push_frame(self, conditional_frame: bool = False) -> Frame: (source)

Push a new frame into the binder.

def put(self, expr: Expression, typ: Type): (source)

Undocumented

def suppress_unreachable_warnings(self): (source)

Undocumented

@contextmanager
def top_frame_context(self) -> Iterator[Frame]: (source)

A variant of frame_context for use at the top level of a namespace (module, function, or class).

def unreachable(self): (source)

Undocumented

def update_from_options(self, frames: list[Frame]) -> bool: (source)

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.

break_frames: list[int] = (source)

Undocumented

continue_frames: list[int] = (source)

Undocumented

declarations: dict[Key, Type|None] = (source)

Undocumented

dependencies: dict[Key, set[Key]] = (source)

Undocumented

Undocumented

last_pop_changed = (source)

Undocumented

Undocumented

options_on_return: list[list[Frame]] = (source)

Undocumented

try_frames: set[int] = (source)

Undocumented

type_assignments = (source)

Undocumented

def _add_dependencies(self, key: Key, value: Key|None = None): (source)

Undocumented

def _cleanse_key(self, key: Key): (source)

Remove all references to a key from the binder.

def _get(self, key: Key, index: int = -1) -> Type|None: (source)

Undocumented

def _get_id(self) -> int: (source)

Undocumented

def _put(self, key: Key, type: Type, index: int = -1): (source)

Undocumented