def visit_index_expr(self, node: IndexExpr) -> Node: new = IndexExpr(self.node(node.base), self.node(node.index)) if node.method_type: new.method_type = self.type(node.method_type) if node.analyzed: new.analyzed = self.visit_type_application(node.analyzed) new.analyzed.set_line(node.analyzed.line) return new
def visit_index_expr(self, node: IndexExpr) -> IndexExpr: new = IndexExpr(self.expr(node.base), self.expr(node.index)) if node.method_type: new.method_type = self.type(node.method_type) if node.analyzed: if isinstance(node.analyzed, TypeApplication): new.analyzed = self.visit_type_application(node.analyzed) else: new.analyzed = self.visit_type_alias_expr(node.analyzed) new.analyzed.set_line(node.analyzed.line) return new
def visit_index_expr(self, e: IndexExpr) -> None: if e.analyzed: # Actually a type application, not indexing. e.analyzed.accept(self) return super().visit_index_expr(e) method_type = e.method_type if self.dynamic_funcs[-1] or isinstance(method_type, AnyType): e.base = self.coerce_to_dynamic(e.base, self.get_type(e.base), self.type_context()) e.index = self.coerce_to_dynamic(e.index, self.get_type(e.index), self.type_context()) else: method_callable = cast(Callable, method_type) e.index = self.coerce(e.index, method_callable.arg_types[0], self.get_type(e.index), self.type_context())
def visit_Subscript(self, n: ast27.Subscript) -> IndexExpr: e = IndexExpr(self.visit(n.value), self.visit(n.slice)) self.set_line(e, n) if isinstance(e.index, SliceExpr): # Slice has no line/column in the raw ast. e.index.line = e.line e.index.column = e.column return e
def get_tvar_access_expression(typ: TypeInfo, tvindex: int, alt: Any, is_java: Any) -> RuntimeTypeVar: """Return a type expression that maps from runtime type variable slots to the type variable in the given class with the given index. For example, assuming class A(Generic[T, S]): ... and class B(A[X, Y[U]], Generic[U]): ...: get_tvar_access_expression(<B>, 1) == RuntimeTypeVar(<self.__tv2.args[0]>) (with <...> represented as nodes) """ # First get the description of how to get from supertype type variables to # a subtype type variable. mapping = get_tvar_access_path(typ, tvindex) # The type checker should have noticed if there is no mapping. Be defensive # and make sure there is one. if mapping is None: raise RuntimeError('Could not find a typevar mapping') # Build the expression for getting at the subtype type variable # progressively. # First read the value of a supertype runtime type variable slot. s = self_expr() # type: Node if alt == OBJECT_VAR: o = '__o' if is_java: o = '__o_{}'.format(typ.name) s = MemberExpr(s, o) expr = MemberExpr(s, tvar_slot_name(mapping[0] - 1, alt)) # type: Node # Then, optionally look into arguments based on the description. for i in mapping[1:]: expr = MemberExpr(expr, 'args') expr = IndexExpr(expr, IntExpr(i - 1)) # Than add a final wrapper so that we have a valid type. return RuntimeTypeVar(expr)
def visit_Subscript(self, n: ast35.Subscript) -> Node: return IndexExpr(self.visit(n.value), self.visit(n.slice))
def visit_Subscript(self, n: ast27.Subscript) -> IndexExpr: return IndexExpr(self.visit(n.value), self.visit(n.slice))
def visit_index_expr(self, node: IndexExpr) -> None: node.analyzed = None # May have been an alias or type application. super().visit_index_expr(node)
def visit_Subscript(self, n: ast27.Subscript) -> IndexExpr: e = IndexExpr(self.visit(n.value), self.visit(n.slice)) return self.set_line(e, n)
def visit_index_expr(self, node: IndexExpr) -> None: node.analyzed = None # was a type alias super().visit_index_expr(node)
def visit_Subscript(self, n): return IndexExpr(self.visit(n.value), self.visit(n.slice))