Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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]]
Exemplo n.º 3
0
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]]
Exemplo n.º 4
0
def unary(state, unused_arg):
    state.stack[-1] = Const.unwrap(state.stack[-1])
Exemplo n.º 5
0
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:]]]]
Exemplo n.º 6
0
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)]