MCPcopy Index your code
hub / github.com/python/mypy / visit_instance

Method visit_instance

mypy/suggestions.py:846–875  ·  view source on GitHub ↗
(self, t: Instance)

Source from the content-addressed store, hash-verified

844 return "Any"
845
846 def visit_instance(self, t: Instance) -> str:
847 s = t.type.fullname or t.type.name or None
848 if s is None:
849 return "<???>"
850
851 mod_obj = split_target(self.graph, s)
852 assert mod_obj
853 mod, obj = mod_obj
854
855 # If a class is imported into the current module, rewrite the reference
856 # to point to the current module. This helps the annotation tool avoid
857 # inserting redundant imports when a type has been reexported.
858 if self.module:
859 parts = obj.split(".") # need to split the object part if it is a nested class
860 tree = self.graph[self.module].tree
861 if tree and parts[0] in tree.names and mod not in tree.names:
862 mod = self.module
863
864 if (mod, obj) == ("builtins", "tuple"):
865 mod, obj = "typing", "Tuple[" + t.args[0].accept(self) + ", ...]"
866 elif t.args:
867 obj += f"[{self.list_str(t.args)}]"
868
869 if mod_obj == ("builtins", "unicode"):
870 return "Text"
871 elif mod == "builtins":
872 return obj
873 else:
874 delim = "." if "." not in obj else ":"
875 return mod + delim + obj
876
877 def visit_tuple_type(self, t: TupleType) -> str:
878 if t.partial_fallback and t.partial_fallback.type:

Callers

nothing calls this directly

Calls 4

split_targetFunction · 0.90
splitMethod · 0.80
list_strMethod · 0.80
acceptMethod · 0.45

Tested by

no test coverage detected