-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't suggest incompatible stub packages (#10610)
Keep track of supported Python versions of legacy bundled packages, and only suggest a stub package if the major Python version is compatible. Fixes #10602.
- Loading branch information
Showing
7 changed files
with
166 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,100 @@ | ||
from typing import Optional | ||
|
||
|
||
class StubInfo: | ||
def __init__(self, name: str, py_version: Optional[int] = None) -> None: | ||
self.name = name | ||
# If None, compatible with py2+py3, if 2/3, only compatible with py2/py3 | ||
self.py_version = py_version | ||
|
||
|
||
def is_legacy_bundled_package(prefix: str, py_version: int) -> bool: | ||
if prefix not in legacy_bundled_packages: | ||
return False | ||
package_ver = legacy_bundled_packages[prefix].py_version | ||
return package_ver is None or package_ver == py_version | ||
|
||
|
||
# Stubs for these third-party packages used to be shipped with mypy. | ||
# | ||
# Map package name to PyPI stub distribution name. | ||
# | ||
# Package name can have one or two components ('a' or 'a.b'). | ||
legacy_bundled_packages = { | ||
'aiofiles': 'types-aiofiles', | ||
'atomicwrites': 'types-atomicwrites', | ||
'attr': 'types-attrs', | ||
'backports': 'types-backports', | ||
'backports_abc': 'types-backports_abc', | ||
'bleach': 'types-bleach', | ||
'boto': 'types-boto', | ||
'cachetools': 'types-cachetools', | ||
'certifi': 'types-certifi', | ||
'characteristic': 'types-characteristic', | ||
'chardet': 'types-chardet', | ||
'click': 'types-click', | ||
'click_spinner': 'types-click-spinner', | ||
'concurrent': 'types-futures', | ||
'contextvars': 'types-contextvars', | ||
'croniter': 'types-croniter', | ||
'cryptography': 'types-cryptography', | ||
'dataclasses': 'types-dataclasses', | ||
'dateparser': 'types-dateparser', | ||
'datetimerange': 'types-DateTimeRange', | ||
'dateutil': 'types-python-dateutil', | ||
'decorator': 'types-decorator', | ||
'deprecated': 'types-Deprecated', | ||
'docutils': 'types-docutils', | ||
'emoji': 'types-emoji', | ||
'enum': 'types-enum34', | ||
'fb303': 'types-fb303', | ||
'filelock': 'types-filelock', | ||
'first': 'types-first', | ||
'flask': 'types-Flask', | ||
'freezegun': 'types-freezegun', | ||
'frozendict': 'types-frozendict', | ||
'geoip2': 'types-geoip2', | ||
'gflags': 'types-python-gflags', | ||
'google.protobuf': 'types-protobuf', | ||
'ipaddress': 'types-ipaddress', | ||
'itsdangerous': 'types-itsdangerous', | ||
'jinja2': 'types-Jinja2', | ||
'jwt': 'types-jwt', | ||
'kazoo': 'types-kazoo', | ||
'markdown': 'types-Markdown', | ||
'markupsafe': 'types-MarkupSafe', | ||
'maxminddb': 'types-maxminddb', | ||
'mock': 'types-mock', | ||
'OpenSSL': 'types-openssl-python', | ||
'orjson': 'types-orjson', | ||
'paramiko': 'types-paramiko', | ||
'pathlib2': 'types-pathlib2', | ||
'pkg_resources': 'types-pkg_resources', | ||
'polib': 'types-polib', | ||
'pycurl': 'types-pycurl', | ||
'pymssql': 'types-pymssql', | ||
'pymysql': 'types-PyMySQL', | ||
'pyrfc3339': 'types-pyRFC3339', | ||
'python2': 'types-six', | ||
'pytz': 'types-pytz', | ||
'pyVmomi': 'types-pyvmomi', | ||
'redis': 'types-redis', | ||
'requests': 'types-requests', | ||
'retry': 'types-retry', | ||
'routes': 'types-Routes', | ||
'scribe': 'types-scribe', | ||
'simplejson': 'types-simplejson', | ||
'singledispatch': 'types-singledispatch', | ||
'six': 'types-six', | ||
'slugify': 'types-python-slugify', | ||
'tabulate': 'types-tabulate', | ||
'termcolor': 'types-termcolor', | ||
'toml': 'types-toml', | ||
'tornado': 'types-tornado', | ||
'typed_ast': 'types-typed-ast', | ||
'tzlocal': 'types-tzlocal', | ||
'ujson': 'types-ujson', | ||
'waitress': 'types-waitress', | ||
'werkzeug': 'types-Werkzeug', | ||
'yaml': 'types-PyYAML', | ||
'aiofiles': StubInfo('types-aiofiles', py_version=3), | ||
'atomicwrites': StubInfo('types-atomicwrites'), | ||
'attr': StubInfo('types-attrs'), | ||
'backports': StubInfo('types-backports'), | ||
'backports_abc': StubInfo('types-backports_abc'), | ||
'bleach': StubInfo('types-bleach'), | ||
'boto': StubInfo('types-boto'), | ||
'cachetools': StubInfo('types-cachetools'), | ||
'certifi': StubInfo('types-certifi'), | ||
'characteristic': StubInfo('types-characteristic'), | ||
'chardet': StubInfo('types-chardet'), | ||
'click': StubInfo('types-click'), | ||
'click_spinner': StubInfo('types-click-spinner'), | ||
'concurrent': StubInfo('types-futures', py_version=2), | ||
'contextvars': StubInfo('types-contextvars', py_version=3), | ||
'croniter': StubInfo('types-croniter'), | ||
'cryptography': StubInfo('types-cryptography'), | ||
'dataclasses': StubInfo('types-dataclasses', py_version=3), | ||
'dateparser': StubInfo('types-dateparser'), | ||
'datetimerange': StubInfo('types-DateTimeRange'), | ||
'dateutil': StubInfo('types-python-dateutil'), | ||
'decorator': StubInfo('types-decorator'), | ||
'deprecated': StubInfo('types-Deprecated'), | ||
'docutils': StubInfo('types-docutils', py_version=3), | ||
'emoji': StubInfo('types-emoji'), | ||
'enum': StubInfo('types-enum34', py_version=2), | ||
'fb303': StubInfo('types-fb303', py_version=2), | ||
'filelock': StubInfo('types-filelock', py_version=3), | ||
'first': StubInfo('types-first'), | ||
'flask': StubInfo('types-Flask'), | ||
'freezegun': StubInfo('types-freezegun', py_version=3), | ||
'frozendict': StubInfo('types-frozendict', py_version=3), | ||
'geoip2': StubInfo('types-geoip2'), | ||
'gflags': StubInfo('types-python-gflags'), | ||
'google.protobuf': StubInfo('types-protobuf'), | ||
'ipaddress': StubInfo('types-ipaddress', py_version=2), | ||
'itsdangerous': StubInfo('types-itsdangerous'), | ||
'jinja2': StubInfo('types-Jinja2'), | ||
'jwt': StubInfo('types-jwt'), | ||
'kazoo': StubInfo('types-kazoo', py_version=2), | ||
'markdown': StubInfo('types-Markdown'), | ||
'markupsafe': StubInfo('types-MarkupSafe'), | ||
'maxminddb': StubInfo('types-maxminddb'), | ||
'mock': StubInfo('types-mock'), | ||
'OpenSSL': StubInfo('types-openssl-python', py_version=2), | ||
'orjson': StubInfo('types-orjson', py_version=3), | ||
'paramiko': StubInfo('types-paramiko'), | ||
'pathlib2': StubInfo('types-pathlib2', py_version=2), | ||
'pkg_resources': StubInfo('types-pkg_resources', py_version=3), | ||
'polib': StubInfo('types-polib'), | ||
'pycurl': StubInfo('types-pycurl'), | ||
'pymssql': StubInfo('types-pymssql', py_version=2), | ||
'pymysql': StubInfo('types-PyMySQL'), | ||
'pyrfc3339': StubInfo('types-pyRFC3339', py_version=3), | ||
'python2': StubInfo('types-six'), | ||
'pytz': StubInfo('types-pytz'), | ||
'pyVmomi': StubInfo('types-pyvmomi'), | ||
'redis': StubInfo('types-redis'), | ||
'requests': StubInfo('types-requests'), | ||
'retry': StubInfo('types-retry'), | ||
'routes': StubInfo('types-Routes', py_version=2), | ||
'scribe': StubInfo('types-scribe', py_version=2), | ||
'simplejson': StubInfo('types-simplejson'), | ||
'singledispatch': StubInfo('types-singledispatch'), | ||
'six': StubInfo('types-six'), | ||
'slugify': StubInfo('types-python-slugify'), | ||
'tabulate': StubInfo('types-tabulate'), | ||
'termcolor': StubInfo('types-termcolor'), | ||
'toml': StubInfo('types-toml'), | ||
'tornado': StubInfo('types-tornado', py_version=2), | ||
'typed_ast': StubInfo('types-typed-ast', py_version=3), | ||
'tzlocal': StubInfo('types-tzlocal'), | ||
'ujson': StubInfo('types-ujson'), | ||
'waitress': StubInfo('types-waitress', py_version=3), | ||
'werkzeug': StubInfo('types-Werkzeug'), | ||
'yaml': StubInfo('types-PyYAML'), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import unittest | ||
|
||
from mypy.stubinfo import is_legacy_bundled_package | ||
|
||
|
||
class TestStubInfo(unittest.TestCase): | ||
def test_is_legacy_bundled_packages(self) -> None: | ||
assert not is_legacy_bundled_package('foobar_asdf', 2) | ||
assert not is_legacy_bundled_package('foobar_asdf', 3) | ||
|
||
assert is_legacy_bundled_package('click', 2) | ||
assert is_legacy_bundled_package('click', 3) | ||
|
||
assert is_legacy_bundled_package('scribe', 2) | ||
assert not is_legacy_bundled_package('scribe', 3) | ||
|
||
assert not is_legacy_bundled_package('dataclasses', 2) | ||
assert is_legacy_bundled_package('dataclasses', 3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters