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

Method add_name

mypy/stubutil.py:664–675  ·  view source on GitHub ↗

Add a name to be imported and return the name reference. The import will be internal to the stub (i.e don't reexport).

(self, fullname: str, require: bool = True)

Source from the content-addressed store, hash-verified

662 return resolved_name
663
664 def add_name(self, fullname: str, require: bool = True) -> str:
665 """Add a name to be imported and return the name reference.
666
667 The import will be internal to the stub (i.e don't reexport).
668 """
669 module, name = fullname.rsplit(".", 1)
670 alias = "_" + name if name in self.defined_names else None
671 while alias in self.defined_names:
672 alias = "_" + alias
673 if module != "builtins" or alias: # don't import from builtins unless needed
674 self.import_tracker.add_import_from(module, [(name, alias)], require=require)
675 return alias or name
676
677 def add_import_line(self, line: str) -> None:
678 """Add a line of text to the import section, unless it's already there."""

Callers 15

set_defined_namesMethod · 0.95
visit_unbound_typeMethod · 0.80
_visit_ref_exprMethod · 0.80
visit_index_exprMethod · 0.80
visit_lambda_exprMethod · 0.80
_get_func_returnMethod · 0.80
get_base_typesMethod · 0.80
process_namedtupleMethod · 0.80
process_typeddictMethod · 0.80

Calls 2

rsplitMethod · 0.80
add_import_fromMethod · 0.80

Tested by

no test coverage detected