def _infer_sequence_for_pyname(pyname): if pyname is None: return None seq = pyname.get_object() args = arguments.ObjectArguments([pyname]) if '__iter__' in seq: iter = seq['__iter__'].get_object().\ get_returned_object(args) if iter is not None and 'next' in iter: holding = iter['next'].get_object().\ get_returned_object(args) return holding
def _self_set(self, context): if self.keys is not None: return new_dict = context.get_pynames(['self', 'd'])[1] if new_dict and isinstance(new_dict.get_object().get_type(), Dict): args = arguments.ObjectArguments([new_dict]) items = new_dict.get_object()['popitem'].\ get_object().get_returned_object(args) context.save_per_name(items) else: holding = _infer_sequence_for_pyname(new_dict) if holding is not None and isinstance(holding.get_type(), Tuple): context.save_per_name(holding)
def _infer_sequence_for_pyname(pyname): if pyname is None: return None seq = pyname.get_object() args = arguments.ObjectArguments([pyname]) if "__iter__" in seq: obj = seq["__iter__"].get_object() if not isinstance(obj, pyobjects.AbstractFunction): return None iter = obj.get_returned_object(args) if iter is not None and "next" in iter: holding = iter["next"].get_object().get_returned_object(args) return holding
def _follow_pyname(assignment, pymodule, lineno=None): assign_node = assignment.ast_node if lineno is None: lineno = _get_lineno_for_node(assign_node) holding_scope = pymodule.get_scope().get_inner_scope_for_line(lineno) pyname = evaluate.eval_node(holding_scope, assign_node) if pyname is not None: result = pyname.get_object() if isinstance(result.get_type(), rope.base.builtins.Property) and \ holding_scope.get_kind() == 'Class': arg = rope.base.pynames.UnboundName( rope.base.pyobjects.PyObject(holding_scope.pyobject)) return pyname, result.get_type().get_property_object( arguments.ObjectArguments([arg])) return pyname, result
def _evaluate_assign_value(self, node, nodes, type_hint=False): for subscript, levels in nodes: instance = evaluate.eval_node(self.scope, subscript.value) args_pynames = [evaluate.eval_node(self.scope, subscript.slice)] value = rope.base.oi.soi._infer_assignment( rope.base.pynames.AssignmentValue(node.value, levels, type_hint=type_hint), self.pymodule) args_pynames.append(rope.base.pynames.UnboundName(value)) if instance is not None and value is not None: pyobject = instance.get_object() if '__setitem__' in pyobject: pyfunction = pyobject['__setitem__'].get_object() args = arguments.ObjectArguments([instance] + args_pynames) self._call(pyfunction, args)
def _follow_evaluations(assignment, pyname, pyobject): new_pyname = pyname tokens = assignment.evaluation.split('.') for token in tokens: call = token.endswith('()') if call: token = token[:-2] if token: pyname = new_pyname new_pyname = _get_attribute(pyobject, token) if new_pyname is not None: pyobject = new_pyname.get_object() if pyobject is not None and call: if isinstance(pyobject, rope.base.pyobjects.AbstractFunction): args = arguments.ObjectArguments([pyname]) pyobject = pyobject.get_returned_object(args) else: pyobject = None if pyobject is None: break if pyobject is not None and assignment.assign_type: return rope.base.pyobjects.PyObject(pyobject) return pyobject
def _Assign(self, node): for child in rope.base.ast.get_child_nodes(node): rope.base.ast.walk(child, self) visitor = _SOAAssignVisitor() nodes = [] for child in node.targets: rope.base.ast.walk(child, visitor) nodes.extend(visitor.nodes) for subscript, levels in nodes: instance = evaluate.eval_node(self.scope, subscript.value) args_pynames = [] args_pynames.append( evaluate.eval_node(self.scope, subscript.slice.value)) value = rope.base.oi.soi._infer_assignment( rope.base.pynames.AssignmentValue(node.value, levels), self.pymodule) args_pynames.append(rope.base.pynames.UnboundName(value)) if instance is not None and value is not None: pyobject = instance.get_object() if '__setitem__' in pyobject: pyfunction = pyobject['__setitem__'].get_object() args = arguments.ObjectArguments([instance] + args_pynames) self._call(pyfunction, args)
def _eval(type_=type_, arg=arg): return type_.get_property_object( arguments.ObjectArguments([arg]))