Esempio n. 1
0
def load_attr(state, arg):
    o = state.stack.pop()
    name = state.get_name(arg)
    if isinstance(o, Const) and hasattr(o.value, name):
        state.stack.append(Const(getattr(o.value, name)))
    elif (isinstance(o, (type, types.ClassType))
          and isinstance(getattr(o, name, None), types.MethodType)):
        state.stack.append(Const(BoundMethod(getattr(o, name))))
    else:
        state.stack.append(Any)
Esempio n. 2
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:]]]
        ]
Esempio n. 3
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)
Esempio n. 4
0
def unary(state, unused_arg):
  state.stack[-1] = Const.unwrap(state.stack[-1])
Esempio 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:]]]]
Esempio n. 6
0
def list_append(state, arg):
  state.stack[-arg] = List[Union[element_type(state.stack[-arg]),
                                 Const.unwrap(state.stack.pop())]]
Esempio n. 7
0
def unary(state, unused_arg):
    state.stack[-1] = Const.unwrap(state.stack[-1])
Esempio n. 8
0
def list_append(state, arg):
    state.stack[-arg] = List[Union[element_type(state.stack[-arg]),
                                   Const.unwrap(state.stack.pop())]]