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

Method create_alias

mypy/semanal.py:854–886  ·  view source on GitHub ↗
(self, tree: MypyFile, target_name: str, alias: str, name: str)

Source from the content-addressed store, hash-verified

852 self.create_alias(tree, target_name, alias, name)
853
854 def create_alias(self, tree: MypyFile, target_name: str, alias: str, name: str) -> None:
855 tag = self.track_incomplete_refs()
856 n = self.lookup_fully_qualified_or_none(target_name)
857 if n:
858 if isinstance(n.node, PlaceholderNode):
859 self.mark_incomplete(name, tree)
860 else:
861 # Found built-in class target. Create alias.
862 target = self.named_type_or_none(target_name, [])
863 assert target is not None
864 # Transform List to List[Any], etc.
865 fix_instance(
866 target, self.fail, self.note, disallow_any=False, options=self.options
867 )
868 alias_node = TypeAlias(
869 target,
870 alias,
871 tree.fullname,
872 line=-1,
873 column=-1, # there is no context
874 no_args=True,
875 normalized=True,
876 )
877 self.add_symbol(name, alias_node, tree)
878 elif self.found_incomplete_ref(tag):
879 # Built-in class target may not ready yet -- defer.
880 self.mark_incomplete(name, tree)
881 else:
882 # Test fixtures may be missing some builtin classes, which is okay.
883 # Kill the placeholder if there is one.
884 if name in tree.names:
885 assert isinstance(tree.names[name].node, PlaceholderNode)
886 del tree.names[name]
887
888 def adjust_public_exports(self) -> None:
889 """Adjust the module visibility of globals due to __all__."""

Callers 2

add_builtin_aliasesMethod · 0.95

Calls 9

track_incomplete_refsMethod · 0.95
mark_incompleteMethod · 0.95
named_type_or_noneMethod · 0.95
add_symbolMethod · 0.95
found_incomplete_refMethod · 0.95
fix_instanceFunction · 0.90
TypeAliasClass · 0.90
isinstanceFunction · 0.85

Tested by

no test coverage detected