def binary_subscr(state, unused_arg): index = state.stack.pop() base = Const.unwrap(state.stack.pop()) if base in (str, unicode): out = base elif (isinstance(index, Const) and isinstance(index.value, int) and isinstance(base, typehints.IndexableTypeConstraint)): try: out = base._constraint_for_index(index.value) except IndexError: out = element_type(base) elif index == slice and isinstance(base, typehints.IndexableTypeConstraint): out = base else: out = element_type(base) state.stack.append(out)
def map_add(state, arg): new_key_type = Const.unwrap(state.stack.pop()) new_value_type = Const.unwrap(state.stack.pop()) state.stack[-arg] = Dict[Union[state.stack[-arg].key_type, new_key_type], Union[state.stack[-arg].value_type, new_value_type]]
def list_append(state, arg): new_element_type = Const.unwrap(state.stack.pop()) state.stack[-arg] = List[Union[element_type(state.stack[-arg]), new_element_type]]
def unary(state, unused_arg): state.stack[-1] = Const.unwrap(state.stack[-1])
def build_tuple(state, arg): if arg == 0: state.stack.append(Tuple[()]) else: state.stack[-arg:] = [Tuple[[Const.unwrap(t) for t in state.stack[-arg:]]]]
def set_add(state, arg): new_element_type = Const.unwrap(state.stack.pop()) state.stack[-arg] = Set[union(element_type(state.stack[-arg]), new_element_type)]