Skip to content

Commit e7f6044

Browse files
authored
Remove logic for legacy bundled stubs (#18372)
For mypy v2
1 parent 2fbfc29 commit e7f6044

5 files changed

Lines changed: 6 additions & 52 deletions

File tree

misc/update-stubinfo.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,10 @@ def main() -> None:
3030

3131
import mypy.stubinfo
3232

33-
mypy_p = set(mypy.stubinfo.non_bundled_packages_flat) | set(
34-
mypy.stubinfo.legacy_bundled_packages
35-
)
33+
mypy_p = set(mypy.stubinfo.non_bundled_packages_flat)
3634

3735
for p in typeshed_p_to_d.keys() & mypy_p:
3836
mypy_d = mypy.stubinfo.non_bundled_packages_flat.get(p)
39-
mypy_d = mypy_d or mypy.stubinfo.legacy_bundled_packages.get(p)
4037
if mypy_d != typeshed_p_to_d[p]:
4138
raise ValueError(
4239
f"stub_distribution mismatch for {p}: {mypy_d} != {typeshed_p_to_d[p]}"

mypy/build.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@
172172
from mypy.plugins.default import DefaultPlugin
173173
from mypy.renaming import LimitedVariableRenameVisitor, VariableRenameVisitor
174174
from mypy.stats import dump_type_stats
175-
from mypy.stubinfo import is_module_from_legacy_bundled_package, stub_distribution_name
175+
from mypy.stubinfo import stub_distribution_name
176176
from mypy.types import Type, instance_cache
177177
from mypy.typestate import reset_global_state, type_state
178178
from mypy.util import json_dumps, json_loads
@@ -3662,19 +3662,6 @@ def find_module_and_diagnose(
36623662

36633663
ignore_missing_imports = options.ignore_missing_imports
36643664

3665-
# Don't honor a global (not per-module) ignore_missing_imports
3666-
# setting for modules that used to have bundled stubs, as
3667-
# otherwise updating mypy can silently result in new false
3668-
# negatives. (Unless there are stubs, but they are incomplete.)
3669-
global_ignore_missing_imports = manager.options.ignore_missing_imports
3670-
if (
3671-
is_module_from_legacy_bundled_package(id)
3672-
and global_ignore_missing_imports
3673-
and not options.ignore_missing_imports_per_module
3674-
and result is ModuleNotFoundReason.APPROVED_STUBS_NOT_INSTALLED
3675-
):
3676-
ignore_missing_imports = False
3677-
36783665
if skip_diagnose:
36793666
raise ModuleNotFound
36803667
if caller_state:

mypy/stubinfo.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
from __future__ import annotations
22

33

4-
def is_module_from_legacy_bundled_package(module: str) -> bool:
5-
top_level = module.split(".", 1)[0]
6-
return top_level in legacy_bundled_packages
7-
8-
94
def stub_distribution_name(module: str) -> str | None:
105
top_level = module.split(".", 1)[0]
116

12-
dist = legacy_bundled_packages.get(top_level)
13-
if dist:
14-
return dist
157
dist = non_bundled_packages_flat.get(top_level)
168
if dist:
179
return dist
@@ -31,7 +23,7 @@ def stub_distribution_name(module: str) -> str | None:
3123
# Stubs for these third-party packages used to be shipped with mypy.
3224
#
3325
# Map package name to PyPI stub distribution name.
34-
legacy_bundled_packages: dict[str, str] = {
26+
_legacy_bundled_packages: dict[str, str] = {
3527
"aiofiles": "types-aiofiles",
3628
"bleach": "types-bleach",
3729
"cachetools": "types-cachetools",
@@ -319,6 +311,7 @@ def stub_distribution_name(module: str) -> str | None:
319311
"lxml": "lxml-stubs", # https://github.com/lxml/lxml-stubs
320312
"scipy": "scipy-stubs", # https://github.com/scipy/scipy-stubs
321313
}
314+
non_bundled_packages_flat.update(_legacy_bundled_packages)
322315

323316

324317
non_bundled_packages_namespace: dict[str, dict[str, str]] = {

mypy/test/teststubinfo.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,10 @@
22

33
import unittest
44

5-
from mypy.stubinfo import (
6-
is_module_from_legacy_bundled_package,
7-
legacy_bundled_packages,
8-
non_bundled_packages_flat,
9-
stub_distribution_name,
10-
)
5+
from mypy.stubinfo import non_bundled_packages_flat, stub_distribution_name
116

127

138
class TestStubInfo(unittest.TestCase):
14-
def test_is_legacy_bundled_packages(self) -> None:
15-
assert not is_module_from_legacy_bundled_package("foobar_asdf")
16-
assert not is_module_from_legacy_bundled_package("PIL")
17-
assert is_module_from_legacy_bundled_package("pycurl")
18-
assert is_module_from_legacy_bundled_package("dateparser")
19-
209
def test_stub_distribution_name(self) -> None:
2110
assert stub_distribution_name("foobar_asdf") is None
2211
assert stub_distribution_name("pycurl") == "types-pycurl"
@@ -30,6 +19,6 @@ def test_stub_distribution_name(self) -> None:
3019
assert stub_distribution_name("google") is None
3120

3221
def test_period_in_top_level(self) -> None:
33-
for packages in (non_bundled_packages_flat, legacy_bundled_packages):
22+
for packages in non_bundled_packages_flat:
3423
for top_level_module in packages:
3524
assert "." not in top_level_module

test-data/unit/pythoneval.test

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,18 +1521,6 @@ x = 0
15211521
mypy: "tmp/typing.py" shadows library module "typing"
15221522
note: A user-defined top-level module with name "typing" is not supported
15231523

1524-
[case testIgnoreImportIfNoPython3StubAvailable]
1525-
# flags: --ignore-missing-imports
1526-
import scribe # No Python 3 stubs available for scribe
1527-
from scribe import x
1528-
import pytz # Python 3 stubs available for pytz
1529-
import foobar_asdf
1530-
import jack # This has a stubs package but was never bundled with mypy, so ignoring works
1531-
[out]
1532-
_testIgnoreImportIfNoPython3StubAvailable.py:4: error: Library stubs not installed for "pytz"
1533-
_testIgnoreImportIfNoPython3StubAvailable.py:4: note: Hint: "python3 -m pip install types-pytz"
1534-
_testIgnoreImportIfNoPython3StubAvailable.py:4: note: (or run "mypy --install-types" to install all missing stub packages)
1535-
_testIgnoreImportIfNoPython3StubAvailable.py:4: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
15361524

15371525
[case testNoPython3StubAvailable]
15381526
import scribe

0 commit comments

Comments
 (0)