|
55 | 55 | DecodeError, |
56 | 56 | decode_python_encoding, |
57 | 57 | get_mypy_comments, |
58 | | - get_top_two_prefixes, |
59 | 58 | hash_digest, |
60 | 59 | is_stub_package_file, |
61 | 60 | is_sub_path, |
|
91 | 90 | from mypy.plugins.default import DefaultPlugin |
92 | 91 | from mypy.renaming import LimitedVariableRenameVisitor, VariableRenameVisitor |
93 | 92 | from mypy.stats import dump_type_stats |
94 | | -from mypy.stubinfo import ( |
95 | | - is_legacy_bundled_package, |
96 | | - legacy_bundled_packages, |
97 | | - non_bundled_packages, |
98 | | - stub_package_name, |
99 | | -) |
| 93 | +from mypy.stubinfo import legacy_bundled_packages, non_bundled_packages, stub_distribution_name |
100 | 94 | from mypy.types import Type |
101 | 95 | from mypy.typestate import reset_global_state, type_state |
102 | 96 | from mypy.version import __version__ |
@@ -2665,14 +2659,18 @@ def find_module_and_diagnose( |
2665 | 2659 | # search path or the module has not been installed. |
2666 | 2660 |
|
2667 | 2661 | ignore_missing_imports = options.ignore_missing_imports |
2668 | | - top_level, second_level = get_top_two_prefixes(id) |
| 2662 | + |
| 2663 | + id_components = id.split(".") |
2669 | 2664 | # Don't honor a global (not per-module) ignore_missing_imports |
2670 | 2665 | # setting for modules that used to have bundled stubs, as |
2671 | 2666 | # otherwise updating mypy can silently result in new false |
2672 | 2667 | # negatives. (Unless there are stubs but they are incomplete.) |
2673 | 2668 | global_ignore_missing_imports = manager.options.ignore_missing_imports |
2674 | 2669 | if ( |
2675 | | - (is_legacy_bundled_package(top_level) or is_legacy_bundled_package(second_level)) |
| 2670 | + any( |
| 2671 | + ".".join(id_components[:i]) in legacy_bundled_packages |
| 2672 | + for i in range(len(id_components), 0, -1) |
| 2673 | + ) |
2676 | 2674 | and global_ignore_missing_imports |
2677 | 2675 | and not options.ignore_missing_imports_per_module |
2678 | 2676 | and result is ModuleNotFoundReason.APPROVED_STUBS_NOT_INSTALLED |
@@ -2790,15 +2788,19 @@ def module_not_found( |
2790 | 2788 | else: |
2791 | 2789 | code = codes.IMPORT |
2792 | 2790 | errors.report(line, 0, msg.format(module=target), code=code) |
2793 | | - top_level, second_level = get_top_two_prefixes(target) |
2794 | | - if second_level in legacy_bundled_packages or second_level in non_bundled_packages: |
2795 | | - top_level = second_level |
| 2791 | + |
| 2792 | + components = target.split(".") |
| 2793 | + for i in range(len(components), 0, -1): |
| 2794 | + module = ".".join(components[:i]) |
| 2795 | + if module in legacy_bundled_packages or module in non_bundled_packages: |
| 2796 | + break |
| 2797 | + |
2796 | 2798 | for note in notes: |
2797 | 2799 | if "{stub_dist}" in note: |
2798 | | - note = note.format(stub_dist=stub_package_name(top_level)) |
| 2800 | + note = note.format(stub_dist=stub_distribution_name(module)) |
2799 | 2801 | errors.report(line, 0, note, severity="note", only_once=True, code=codes.IMPORT) |
2800 | 2802 | if reason is ModuleNotFoundReason.APPROVED_STUBS_NOT_INSTALLED: |
2801 | | - manager.missing_stub_packages.add(stub_package_name(top_level)) |
| 2803 | + manager.missing_stub_packages.add(stub_distribution_name(module)) |
2802 | 2804 | errors.set_import_context(save_import_context) |
2803 | 2805 |
|
2804 | 2806 |
|
|
0 commit comments