def visit_type_var(self, t): if t.id > 0 or self.func_tvars: if t.repr is not None: # Give a representation for the dynamic type. tok = Token('any') tok.pre = t.repr.name.pre return Any(t.line, AnyRepr(tok)) else: return Any() else: return t
class ReplaceTypeVarsVisitor(TypeTranslator): # Only override type variable handling; otherwise perform an indentity # transformation. bool func_tvars void __init__(self, bool func_tvars): self.func_tvars = func_tvars Typ visit_type_var(self, TypeVar t): if t.id > 0 or self.func_tvars: if t.repr is not None: # Give a representation for the dynamic type. tok = Token('any') tok.pre = t.repr.name.pre return Any(t.line, AnyRepr(tok)) else: return Any() else: return t Typ replace_func_type_vars(Typ typ): """Replace type variables in a type with the None (empty) type.""" return typ.accept(ReplaceFuncTypeVarsVisitor()) class ReplaceFuncTypeVarsVisitor(TypeTranslator): Typ visit_type_var(self, TypeVar t): if t.id < 0: