From ee8eb89b41469ca97de0a481c11a6d4ecfe4fc9c Mon Sep 17 00:00:00 2001 From: Shantanu Jain Date: Sat, 17 Jan 2026 17:55:39 -0800 Subject: [PATCH] rebase --- misc/update-stubinfo.py | 5 +---- mypy/build.py | 15 +-------------- mypy/stubinfo.py | 11 ++--------- mypy/test/teststubinfo.py | 15 ++------------- test-data/unit/pythoneval.test | 12 ------------ 5 files changed, 6 insertions(+), 52 deletions(-) diff --git a/misc/update-stubinfo.py b/misc/update-stubinfo.py index 4a5b9a40c408..a3558ace082e 100644 --- a/misc/update-stubinfo.py +++ b/misc/update-stubinfo.py @@ -30,13 +30,10 @@ def main() -> None: import mypy.stubinfo - mypy_p = set(mypy.stubinfo.non_bundled_packages_flat) | set( - mypy.stubinfo.legacy_bundled_packages - ) + mypy_p = set(mypy.stubinfo.non_bundled_packages_flat) for p in typeshed_p_to_d.keys() & mypy_p: mypy_d = mypy.stubinfo.non_bundled_packages_flat.get(p) - mypy_d = mypy_d or mypy.stubinfo.legacy_bundled_packages.get(p) if mypy_d != typeshed_p_to_d[p]: raise ValueError( f"stub_distribution mismatch for {p}: {mypy_d} != {typeshed_p_to_d[p]}" diff --git a/mypy/build.py b/mypy/build.py index f7e13cfb5791..8fb91c370553 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -132,7 +132,7 @@ from mypy.plugins.default import DefaultPlugin from mypy.renaming import LimitedVariableRenameVisitor, VariableRenameVisitor from mypy.stats import dump_type_stats -from mypy.stubinfo import is_module_from_legacy_bundled_package, stub_distribution_name +from mypy.stubinfo import stub_distribution_name from mypy.types import Type, instance_cache from mypy.typestate import reset_global_state, type_state from mypy.util import json_dumps, json_loads @@ -2914,19 +2914,6 @@ def find_module_and_diagnose( ignore_missing_imports = options.ignore_missing_imports - # Don't honor a global (not per-module) ignore_missing_imports - # setting for modules that used to have bundled stubs, as - # otherwise updating mypy can silently result in new false - # negatives. (Unless there are stubs but they are incomplete.) - global_ignore_missing_imports = manager.options.ignore_missing_imports - if ( - is_module_from_legacy_bundled_package(id) - and global_ignore_missing_imports - and not options.ignore_missing_imports_per_module - and result is ModuleNotFoundReason.APPROVED_STUBS_NOT_INSTALLED - ): - ignore_missing_imports = False - if skip_diagnose: raise ModuleNotFound if caller_state: diff --git a/mypy/stubinfo.py b/mypy/stubinfo.py index 42e53ba21c84..4f2fd2584796 100644 --- a/mypy/stubinfo.py +++ b/mypy/stubinfo.py @@ -1,17 +1,9 @@ from __future__ import annotations -def is_module_from_legacy_bundled_package(module: str) -> bool: - top_level = module.split(".", 1)[0] - return top_level in legacy_bundled_packages - - def stub_distribution_name(module: str) -> str | None: top_level = module.split(".", 1)[0] - dist = legacy_bundled_packages.get(top_level) - if dist: - return dist dist = non_bundled_packages_flat.get(top_level) if dist: return dist @@ -31,7 +23,7 @@ def stub_distribution_name(module: str) -> str | None: # Stubs for these third-party packages used to be shipped with mypy. # # Map package name to PyPI stub distribution name. -legacy_bundled_packages: dict[str, str] = { +_legacy_bundled_packages: dict[str, str] = { "aiofiles": "types-aiofiles", "bleach": "types-bleach", "cachetools": "types-cachetools", @@ -309,6 +301,7 @@ def stub_distribution_name(module: str) -> str | None: "lxml": "lxml-stubs", # https://github.com/lxml/lxml-stubs "scipy": "scipy-stubs", # https://github.com/scipy/scipy-stubs } +non_bundled_packages_flat.update(_legacy_bundled_packages) non_bundled_packages_namespace: dict[str, dict[str, str]] = { diff --git a/mypy/test/teststubinfo.py b/mypy/test/teststubinfo.py index ae34e78f98c6..25becb4a1aea 100644 --- a/mypy/test/teststubinfo.py +++ b/mypy/test/teststubinfo.py @@ -2,21 +2,10 @@ import unittest -from mypy.stubinfo import ( - is_module_from_legacy_bundled_package, - legacy_bundled_packages, - non_bundled_packages_flat, - stub_distribution_name, -) +from mypy.stubinfo import non_bundled_packages_flat, stub_distribution_name class TestStubInfo(unittest.TestCase): - def test_is_legacy_bundled_packages(self) -> None: - assert not is_module_from_legacy_bundled_package("foobar_asdf") - assert not is_module_from_legacy_bundled_package("PIL") - assert is_module_from_legacy_bundled_package("pycurl") - assert is_module_from_legacy_bundled_package("dateparser") - def test_stub_distribution_name(self) -> None: assert stub_distribution_name("foobar_asdf") is None assert stub_distribution_name("pycurl") == "types-pycurl" @@ -30,6 +19,6 @@ def test_stub_distribution_name(self) -> None: assert stub_distribution_name("google") is None def test_period_in_top_level(self) -> None: - for packages in (non_bundled_packages_flat, legacy_bundled_packages): + for packages in non_bundled_packages_flat: for top_level_module in packages: assert "." not in top_level_module diff --git a/test-data/unit/pythoneval.test b/test-data/unit/pythoneval.test index 9f057042926d..e224905e2dcb 100644 --- a/test-data/unit/pythoneval.test +++ b/test-data/unit/pythoneval.test @@ -1521,18 +1521,6 @@ x = 0 mypy: "tmp/typing.py" shadows library module "typing" note: A user-defined top-level module with name "typing" is not supported -[case testIgnoreImportIfNoPython3StubAvailable] -# flags: --ignore-missing-imports -import scribe # No Python 3 stubs available for scribe -from scribe import x -import pytz # Python 3 stubs available for pytz -import foobar_asdf -import jack # This has a stubs package but was never bundled with mypy, so ignoring works -[out] -_testIgnoreImportIfNoPython3StubAvailable.py:4: error: Library stubs not installed for "pytz" -_testIgnoreImportIfNoPython3StubAvailable.py:4: note: Hint: "python3 -m pip install types-pytz" -_testIgnoreImportIfNoPython3StubAvailable.py:4: note: (or run "mypy --install-types" to install all missing stub packages) -_testIgnoreImportIfNoPython3StubAvailable.py:4: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports [case testNoPython3StubAvailable] import scribe