Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove logic for legacy bundled stubs #18372

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,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
from mypy.typestate import reset_global_state, type_state
from mypy.util import json_dumps, json_loads
Expand Down Expand Up @@ -2661,19 +2661,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:
Expand Down
96 changes: 41 additions & 55 deletions mypy/stubinfo.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -28,53 +20,6 @@ def stub_distribution_name(module: str) -> str | None:
return 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] = {
"aiofiles": "types-aiofiles",
"bleach": "types-bleach",
"boto": "types-boto",
"cachetools": "types-cachetools",
"click_spinner": "types-click-spinner",
"contextvars": "types-contextvars",
"croniter": "types-croniter",
"dataclasses": "types-dataclasses",
"dateparser": "types-dateparser",
"dateutil": "types-python-dateutil",
"decorator": "types-decorator",
"deprecated": "types-Deprecated",
"docutils": "types-docutils",
"first": "types-first",
"gflags": "types-python-gflags",
"markdown": "types-Markdown",
"mock": "types-mock",
"OpenSSL": "types-pyOpenSSL",
"paramiko": "types-paramiko",
"pkg_resources": "types-setuptools",
"polib": "types-polib",
"pycurl": "types-pycurl",
"pymysql": "types-PyMySQL",
"pyrfc3339": "types-pyRFC3339",
"python2": "types-six",
"pytz": "types-pytz",
"pyVmomi": "types-pyvmomi",
"redis": "types-redis",
"requests": "types-requests",
"retry": "types-retry",
"simplejson": "types-simplejson",
"singledispatch": "types-singledispatch",
"six": "types-six",
"slugify": "types-python-slugify",
"tabulate": "types-tabulate",
"toml": "types-toml",
"typed_ast": "types-typed-ast",
"tzlocal": "types-tzlocal",
"ujson": "types-ujson",
"waitress": "types-waitress",
"yaml": "types-PyYAML",
}

# Map package name to PyPI stub distribution name from typeshed.
# Stubs for these packages were never bundled with mypy. Don't
# include packages that have a release that includes PEP 561 type
Expand All @@ -87,44 +32,58 @@ def stub_distribution_name(module: str) -> str | None:
non_bundled_packages_flat: dict[str, str] = {
"_cffi_backend": "types-cffi",
"_win32typing": "types-pywin32",
"aiofiles": "types-aiofiles",
"antlr4": "types-antlr4-python3-runtime",
"assertpy": "types-assertpy",
"atheris": "types-atheris",
"authlib": "types-Authlib",
"aws_xray_sdk": "types-aws-xray-sdk",
"babel": "types-babel",
"bleach": "types-bleach",
"boltons": "types-boltons",
"boto": "types-boto",
"braintree": "types-braintree",
"bs4": "types-beautifulsoup4",
"bugbear": "types-flake8-bugbear",
"cachetools": "types-cachetools",
"caldav": "types-caldav",
"capturer": "types-capturer",
"cffi": "types-cffi",
"chevron": "types-chevron",
"click_default_group": "types-click-default-group",
"click_log": "types-click-log",
"click_spinner": "types-click-spinner",
"click_web": "types-click-web",
"colorama": "types-colorama",
"commctrl": "types-pywin32",
"commonmark": "types-commonmark",
"consolemenu": "types-console-menu",
"contextvars": "types-contextvars",
"corus": "types-corus",
"croniter": "types-croniter",
"cronlog": "types-python-crontab",
"crontab": "types-python-crontab",
"crontabs": "types-python-crontab",
"d3dshot": "types-D3DShot",
"dataclasses": "types-dataclasses",
"datemath": "types-python-datemath",
"dateparser_data": "types-dateparser",
"dateparser": "types-dateparser",
"dateutil": "types-python-dateutil",
"dde": "types-pywin32",
"decorator": "types-decorator",
"defusedxml": "types-defusedxml",
"deprecated": "types-Deprecated",
"docker": "types-docker",
"dockerfile_parse": "types-dockerfile-parse",
"docopt": "types-docopt",
"docutils": "types-docutils",
"editdistance": "types-editdistance",
"entrypoints": "types-entrypoints",
"exifread": "types-ExifRead",
"fanstatic": "types-fanstatic",
"farmhash": "types-pyfarmhash",
"first": "types-first",
"flake8_2020": "types-flake8-2020",
"flake8_builtins": "types-flake8-builtins",
"flake8_docstrings": "types-flake8-docstrings",
Expand All @@ -139,6 +98,7 @@ def stub_distribution_name(module: str) -> str | None:
"fpdf": "types-fpdf2",
"gdb": "types-gdb",
"gevent": "types-gevent",
"gflags": "types-python-gflags",
"greenlet": "types-greenlet",
"hdbcli": "types-hdbcli",
"html5lib": "types-html5lib",
Expand All @@ -165,8 +125,10 @@ def stub_distribution_name(module: str) -> str | None:
"lupa": "types-lupa",
"lzstring": "types-lzstring",
"m3u8": "types-m3u8",
"markdown": "types-Markdown",
"mmapfile": "types-pywin32",
"mmsystem": "types-pywin32",
"mock": "types-mock",
"mypy_extensions": "types-mypy-extensions",
"MySQLdb": "types-mysqlclient",
"nanoid": "types-nanoid",
Expand All @@ -181,7 +143,9 @@ def stub_distribution_name(module: str) -> str | None:
"odbc": "types-pywin32",
"olefile": "types-olefile",
"openpyxl": "types-openpyxl",
"OpenSSL": "types-pyOpenSSL",
"opentracing": "types-opentracing",
"paramiko": "types-paramiko",
"parsimonious": "types-parsimonious",
"passlib": "types-passlib",
"passpy": "types-passpy",
Expand All @@ -190,34 +154,45 @@ def stub_distribution_name(module: str) -> str | None:
"perfmon": "types-pywin32",
"pexpect": "types-pexpect",
"PIL": "types-Pillow",
"pkg_resources": "types-setuptools",
"playhouse": "types-peewee",
"playsound": "types-playsound",
"polib": "types-polib",
"portpicker": "types-portpicker",
"psutil": "types-psutil",
"psycopg2": "types-psycopg2",
"pyasn1": "types-pyasn1",
"pyaudio": "types-pyaudio",
"pyautogui": "types-PyAutoGUI",
"pycocotools": "types-pycocotools",
"pycurl": "types-pycurl",
"pyflakes": "types-pyflakes",
"pygit2": "types-pygit2",
"pygments": "types-Pygments",
"pyi_splash": "types-pyinstaller",
"PyInstaller": "types-pyinstaller",
"pymysql": "types-PyMySQL",
"pynput": "types-pynput",
"pyrfc3339": "types-pyRFC3339",
"pyscreeze": "types-PyScreeze",
"pysftp": "types-pysftp",
"pytest_lazyfixture": "types-pytest-lazy-fixture",
"python_http_client": "types-python-http-client",
"python2": "types-six",
"pythoncom": "types-pywin32",
"pythonwin": "types-pywin32",
"pytz": "types-pytz",
"pyVmomi": "types-pyvmomi",
"pywintypes": "types-pywin32",
"qrbill": "types-qrbill",
"qrcode": "types-qrcode",
"redis": "types-redis",
"regex": "types-regex",
"regutil": "types-pywin32",
"reportlab": "types-reportlab",
"requests_oauthlib": "types-requests-oauthlib",
"requests": "types-requests",
"retry": "types-retry",
"RPi": "types-RPi.GPIO",
"s2clientprotocol": "types-s2clientprotocol",
"sass": "types-libsass",
Expand All @@ -228,26 +203,36 @@ def stub_distribution_name(module: str) -> str | None:
"servicemanager": "types-pywin32",
"setuptools": "types-setuptools",
"shapely": "types-shapely",
"simplejson": "types-simplejson",
"singledispatch": "types-singledispatch",
"six": "types-six",
"slugify": "types-python-slugify",
"slumber": "types-slumber",
"sspicon": "types-pywin32",
"stdlib_list": "types-stdlib-list",
"str2bool": "types-str2bool",
"stripe": "types-stripe",
"tabulate": "types-tabulate",
"tensorflow": "types-tensorflow",
"tgcrypto": "types-TgCrypto",
"timer": "types-pywin32",
"toml": "types-toml",
"toposort": "types-toposort",
"tqdm": "types-tqdm",
"translationstring": "types-translationstring",
"tree_sitter_languages": "types-tree-sitter-languages",
"tree_sitter": "types-tree-sitter",
"ttkthemes": "types-ttkthemes",
"typed_ast": "types-typed-ast",
"tzlocal": "types-tzlocal",
"ujson": "types-ujson",
"unidiff": "types-unidiff",
"untangle": "types-untangle",
"usersettings": "types-usersettings",
"uwsgi": "types-uWSGI",
"uwsgidecorators": "types-uWSGI",
"vobject": "types-vobject",
"waitress": "types-waitress",
"webob": "types-WebOb",
"whatthepatch": "types-whatthepatch",
"win2kras": "types-pywin32",
Expand Down Expand Up @@ -305,6 +290,7 @@ def stub_distribution_name(module: str) -> str | None:
"xdgenvpy": "types-xdgenvpy",
"Xlib": "types-python-xlib",
"xmltodict": "types-xmltodict",
"yaml": "types-PyYAML",
"zstd": "types-zstd",
"zxcvbn": "types-zxcvbn",
# Stub packages that are not from typeshed
Expand Down
14 changes: 2 additions & 12 deletions mypy/test/teststubinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +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("dataclasses")

def test_stub_distribution_name(self) -> None:
assert stub_distribution_name("foobar_asdf") is None
Expand All @@ -29,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
12 changes: 0 additions & 12 deletions test-data/unit/pythoneval.test
Original file line number Diff line number Diff line change
Expand Up @@ -1503,18 +1503,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 python2 # Python 3 stubs available for python2
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 "python2"
_testIgnoreImportIfNoPython3StubAvailable.py:4: note: Hint: "python3 -m pip install types-six"
_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
Expand Down
Loading