Example #1
0
def symmetric_binary_op(state, unused_arg):
  # TODO(robertwb): This may not be entirely correct...
  b, a = state.stack.pop(), 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)
Example #2
0
def symmetric_binary_op(state, unused_arg):
    # TODO(robertwb): This may not be entirely correct...
    b, a = state.stack.pop(), 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)
Example #3
0
def binary_subscr(state, unused_arg):
  tos = state.stack.pop()
  if tos in (str, unicode):
    out = tos
  else:
    out = element_type(tos)
  state.stack.append(out)
Example #4
0
def binary_subscr(state, unused_arg):
    tos = state.stack.pop()
    if tos in (str, unicode):
        out = tos
    else:
        out = element_type(tos)
    state.stack.append(out)
Example #5
0
def unpack_sequence(state, arg):
  t = state.stack.pop()
  if isinstance(t, Const):
    try:
      unpacked = [Const(ti) for ti in t.value]
      if len(unpacked) != arg:
        unpacked = [Any] * arg
    except TypeError:
      unpacked = [Any] * arg
  elif (isinstance(t, typehints.TupleHint.TupleConstraint)
        and len(t.tuple_types) == arg):
    unpacked = list(t.tuple_types)
  else:
    unpacked = [element_type(t)] * arg
  state.stack += reversed(unpacked)
Example #6
0
def unpack_sequence(state, arg):
    t = state.stack.pop()
    if isinstance(t, Const):
        try:
            unpacked = [Const(ti) for ti in t.value]
            if len(unpacked) != arg:
                unpacked = [Any] * arg
        except TypeError:
            unpacked = [Any] * arg
    elif (isinstance(t, typehints.TupleHint.TupleConstraint)
          and len(t.tuple_types) == arg):
        unpacked = list(t.tuple_types)
    else:
        unpacked = [element_type(t)] * arg
    state.stack += reversed(unpacked)
Example #7
0
def get_iter(state, unused_arg):
  state.stack.append(Iterable[element_type(state.stack.pop())])
Example #8
0
def list_append(state, arg):
  state.stack[-arg] = List[Union[element_type(state.stack[-arg]),
                                 Const.unwrap(state.stack.pop())]]
Example #9
0
def get_iter(state, unused_arg):
    state.stack.append(Iterable[element_type(state.stack.pop())])
Example #10
0
def list_append(state, arg):
    state.stack[-arg] = List[Union[element_type(state.stack[-arg]),
                                   Const.unwrap(state.stack.pop())]]