|
57 | 57 | DecodeError, |
58 | 58 | decode_python_encoding, |
59 | 59 | get_mypy_comments, |
60 | | - get_top_two_prefixes, |
61 | 60 | hash_digest, |
62 | 61 | is_stub_package_file, |
63 | 62 | is_sub_path, |
|
97 | 96 | is_legacy_bundled_package, |
98 | 97 | legacy_bundled_packages, |
99 | 98 | non_bundled_packages, |
100 | | - stub_package_name, |
| 99 | + stub_distribution_name, |
101 | 100 | ) |
102 | 101 | from mypy.types import Type |
103 | 102 | from mypy.typestate import reset_global_state, type_state |
@@ -2664,14 +2663,15 @@ def find_module_and_diagnose( |
2664 | 2663 | # search path or the module has not been installed. |
2665 | 2664 |
|
2666 | 2665 | ignore_missing_imports = options.ignore_missing_imports |
2667 | | - top_level, second_level = get_top_two_prefixes(id) |
| 2666 | + |
| 2667 | + id_components = id.split(".") |
2668 | 2668 | # Don't honor a global (not per-module) ignore_missing_imports |
2669 | 2669 | # setting for modules that used to have bundled stubs, as |
2670 | 2670 | # otherwise updating mypy can silently result in new false |
2671 | 2671 | # negatives. (Unless there are stubs but they are incomplete.) |
2672 | 2672 | global_ignore_missing_imports = manager.options.ignore_missing_imports |
2673 | 2673 | if ( |
2674 | | - (is_legacy_bundled_package(top_level) or is_legacy_bundled_package(second_level)) |
| 2674 | + any(".".join(id_components[:i]) in legacy_bundled_packages for i in range(len(id_components), 0, -1)) |
2675 | 2675 | and global_ignore_missing_imports |
2676 | 2676 | and not options.ignore_missing_imports_per_module |
2677 | 2677 | and result is ModuleNotFoundReason.APPROVED_STUBS_NOT_INSTALLED |
@@ -2780,15 +2780,19 @@ def module_not_found( |
2780 | 2780 | daemon = manager.options.fine_grained_incremental |
2781 | 2781 | msg, notes = reason.error_message_templates(daemon) |
2782 | 2782 | errors.report(line, 0, msg.format(module=target), code=codes.IMPORT) |
2783 | | - top_level, second_level = get_top_two_prefixes(target) |
2784 | | - if second_level in legacy_bundled_packages or second_level in non_bundled_packages: |
2785 | | - top_level = second_level |
| 2783 | + |
| 2784 | + components = target.split(".") |
| 2785 | + for i in range(len(components), 0, -1): |
| 2786 | + module = ".".join(components[:i]) |
| 2787 | + if module in legacy_bundled_packages or module in non_bundled_packages: |
| 2788 | + break |
| 2789 | + |
2786 | 2790 | for note in notes: |
2787 | 2791 | if "{stub_dist}" in note: |
2788 | | - note = note.format(stub_dist=stub_package_name(top_level)) |
| 2792 | + note = note.format(stub_dist=stub_distribution_name(module)) |
2789 | 2793 | errors.report(line, 0, note, severity="note", only_once=True, code=codes.IMPORT) |
2790 | 2794 | if reason is ModuleNotFoundReason.APPROVED_STUBS_NOT_INSTALLED: |
2791 | | - manager.missing_stub_packages.add(stub_package_name(top_level)) |
| 2795 | + manager.missing_stub_packages.add(stub_distribution_name(module)) |
2792 | 2796 | errors.set_import_context(save_import_context) |
2793 | 2797 |
|
2794 | 2798 |
|
|
0 commit comments