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

Function in_partial_package

mypy/build.py:3883–3912  ·  view source on GitHub ↗

Check if a missing module can potentially be a part of a package. This checks if there is any existing parent __init__.pyi stub that defines a module-level __getattr__ (a.k.a. partial stub package).

(id: str, manager: BuildManager)

Source from the content-addressed store, hash-verified

3881
3882
3883def in_partial_package(id: str, manager: BuildManager) -> bool:
3884 """Check if a missing module can potentially be a part of a package.
3885
3886 This checks if there is any existing parent __init__.pyi stub that
3887 defines a module-level __getattr__ (a.k.a. partial stub package).
3888 """
3889 while "." in id:
3890 ancestor, _ = id.rsplit(".", 1)
3891 if ancestor in manager.known_partial_packages:
3892 return manager.known_partial_packages[ancestor]
3893 if ancestor in manager.modules:
3894 ancestor_mod: MypyFile | None = manager.modules[ancestor]
3895 else:
3896 # Ancestor is not in build, try quickly if we can find it.
3897 try:
3898 ancestor_st = State.new_state(
3899 id=ancestor, path=None, source=None, manager=manager, temporary=True
3900 )
3901 except (ModuleNotFound, CompileError):
3902 ancestor_mod = None
3903 else:
3904 ancestor_mod = ancestor_st.tree
3905 # We will not need this anymore.
3906 ancestor_st.tree = None
3907 if ancestor_mod is not None:
3908 # Bail out soon, complete subpackage found
3909 manager.known_partial_packages[ancestor] = ancestor_mod.is_partial_stub_package
3910 return ancestor_mod.is_partial_stub_package
3911 id = ancestor
3912 return False
3913
3914
3915def module_not_found(

Callers 1

find_module_and_diagnoseFunction · 0.85

Calls 2

rsplitMethod · 0.80
new_stateMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…