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)
| 3881 | |
| 3882 | |
| 3883 | def 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 | |
| 3915 | def module_not_found( |
no test coverage detected
searching dependent graphs…