Esempio n. 1
0
def dict_update(state, arg):
    other = state.stack.pop()
    base = state.stack[-arg]
    if isinstance(base, typehints.Dict.DictConstraint):
        base_key_type = base.key_type
        base_value_type = base.value_type
    else:
        base_key_type = Any
        base_value_type = Any
    if isinstance(other, typehints.Dict.DictConstraint):
        other_key_type = other.key_type
        other_value_type = other.value_type
    else:
        other_key_type, other_value_type = key_value_types(element_type(other))
    state.stack[-arg] = Dict[union(base_key_type, other_key_type),
                             union(base_value_type, other_value_type)]
Esempio n. 2
0
def symmetric_binary_op(state, unused_arg):
  # TODO(robertwb): This may not be entirely correct...
  b, a = Const.unwrap(state.stack.pop()), Const.unwrap(state.stack.pop())
  if a == b:
    state.stack.append(a)
  elif type(a) == type(b) and isinstance(a, typehints.SequenceTypeConstraint):
    state.stack.append(type(a)(union(element_type(a), element_type(b))))
  else:
    state.stack.append(Any)
Esempio n. 3
0
def binary_true_divide(state, unused_arg):
    u = union(state.stack.pop(), state.stack.pop)
    if u == int:
        state.stack.append(float)
    else:
        state.stack.append(u)
Esempio n. 4
0
def set_update(state, arg):
    other = state.stack.pop()
    base = state.stack[-arg]
    state.stack[-arg] = Set[union(element_type(base), element_type(other))]
Esempio n. 5
0
def list_extend(state, arg):
    tail = state.stack.pop()
    base = state.stack[-arg]
    state.stack[-arg] = List[union(element_type(base), element_type(tail))]
Esempio 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)]
Esempio n. 7
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)]