diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6bbc96671..d441b71fb 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -159,8 +159,6 @@ supported: When the stubs are updated to a newer version of the library, the version of the stub should be bumped (note that previous versions are still available on PyPI). -* `python2` (default: `false`): If set to `true`, the top-level stubs - support both Python 2 and Python 3. * `requires` (optional): A list of other stub packages or packages with type information that are imported by the stubs in this package. Only packages generated by typeshed or required by the upstream package are allowed to diff --git a/stubs/Deprecated/METADATA.toml b/stubs/Deprecated/METADATA.toml index 1f0b2e4bf..3d4d518df 100644 --- a/stubs/Deprecated/METADATA.toml +++ b/stubs/Deprecated/METADATA.toml @@ -1,3 +1,2 @@ version = "1.2.*" -python2 = true requires = [] diff --git a/stubs/backports.ssl_match_hostname/METADATA.toml b/stubs/backports.ssl_match_hostname/METADATA.toml index 839f7d3a9..1cc454093 100644 --- a/stubs/backports.ssl_match_hostname/METADATA.toml +++ b/stubs/backports.ssl_match_hostname/METADATA.toml @@ -1,2 +1 @@ version = "3.7.*" -python2 = true diff --git a/stubs/certifi/METADATA.toml b/stubs/certifi/METADATA.toml index a75d69563..182888f03 100644 --- a/stubs/certifi/METADATA.toml +++ b/stubs/certifi/METADATA.toml @@ -1,2 +1 @@ version = "2021.10.8" -python2 = true diff --git a/stubs/characteristic/METADATA.toml b/stubs/characteristic/METADATA.toml index 199895dd5..5adb9ee2e 100644 --- a/stubs/characteristic/METADATA.toml +++ b/stubs/characteristic/METADATA.toml @@ -1,2 +1 @@ version = "14.3.*" -python2 = true diff --git a/stubs/colorama/METADATA.toml b/stubs/colorama/METADATA.toml index cea6c7b21..582104d3a 100644 --- a/stubs/colorama/METADATA.toml +++ b/stubs/colorama/METADATA.toml @@ -1,2 +1 @@ version = "0.4.*" -python2 = true \ No newline at end of file diff --git a/stubs/docopt/METADATA.toml b/stubs/docopt/METADATA.toml index ce19e8f4b..61c37e66a 100644 --- a/stubs/docopt/METADATA.toml +++ b/stubs/docopt/METADATA.toml @@ -1,3 +1,2 @@ # Prior to v0.6, docopt() had only 3 optional args version = "0.6.*" -python2 = true \ No newline at end of file diff --git a/stubs/first/METADATA.toml b/stubs/first/METADATA.toml index 722943771..58bc38349 100644 --- a/stubs/first/METADATA.toml +++ b/stubs/first/METADATA.toml @@ -1,2 +1 @@ version = "2.0.*" -python2 = true diff --git a/stubs/mypy-extensions/METADATA.toml b/stubs/mypy-extensions/METADATA.toml index 79b51931e..582104d3a 100644 --- a/stubs/mypy-extensions/METADATA.toml +++ b/stubs/mypy-extensions/METADATA.toml @@ -1,2 +1 @@ version = "0.4.*" -python2 = true diff --git a/stubs/pyaudio/METADATA.toml b/stubs/pyaudio/METADATA.toml index c31d59608..0cd32aff1 100644 --- a/stubs/pyaudio/METADATA.toml +++ b/stubs/pyaudio/METADATA.toml @@ -1,3 +1,2 @@ version = "0.2.*" -python2 = true stubtest_apt_dependencies = ["portaudio19-dev"] diff --git a/stubs/pytz/METADATA.toml b/stubs/pytz/METADATA.toml index 0bdf10963..d115c67a0 100644 --- a/stubs/pytz/METADATA.toml +++ b/stubs/pytz/METADATA.toml @@ -1,2 +1 @@ version = "2021.3" -python2 = true diff --git a/stubs/retry/METADATA.toml b/stubs/retry/METADATA.toml index 6f2870bcf..51e869b47 100644 --- a/stubs/retry/METADATA.toml +++ b/stubs/retry/METADATA.toml @@ -1,2 +1 @@ version = "0.9.*" -python2 = true diff --git a/stubs/singledispatch/METADATA.toml b/stubs/singledispatch/METADATA.toml index 839f7d3a9..1cc454093 100644 --- a/stubs/singledispatch/METADATA.toml +++ b/stubs/singledispatch/METADATA.toml @@ -1,2 +1 @@ version = "3.7.*" -python2 = true diff --git a/stubs/tabulate/METADATA.toml b/stubs/tabulate/METADATA.toml index 78fa4d13f..29511ee7d 100644 --- a/stubs/tabulate/METADATA.toml +++ b/stubs/tabulate/METADATA.toml @@ -1,2 +1 @@ version = "0.8.*" -python2 = true diff --git a/stubs/xxhash/METADATA.toml b/stubs/xxhash/METADATA.toml index 722943771..58bc38349 100644 --- a/stubs/xxhash/METADATA.toml +++ b/stubs/xxhash/METADATA.toml @@ -1,2 +1 @@ version = "2.0.*" -python2 = true diff --git a/tests/check_consistent.py b/tests/check_consistent.py index 6239321bf..2b6ed496a 100755 --- a/tests/check_consistent.py +++ b/tests/check_consistent.py @@ -18,7 +18,7 @@ import re import tomli consistent_files = [{"stdlib/@python2/builtins.pyi", "stdlib/@python2/__builtin__.pyi"}] -metadata_keys = {"version", "python2", "requires", "extra_description", "obsolete_since", "stubtest", "stubtest_apt_dependencies"} +metadata_keys = {"version", "requires", "extra_description", "obsolete_since", "stubtest", "stubtest_apt_dependencies"} allowed_files = {"README.md"} @@ -162,7 +162,6 @@ def check_metadata(): assert re.fullmatch(r"\d+(\.\d+)+|\d+(\.\d+)*\.\*", version), msg for key in data: assert key in metadata_keys, f"Unexpected key {key} for {distribution}" - assert isinstance(data.get("python2", False), bool), f"Invalid python2 value for {distribution}" assert isinstance(data.get("requires", []), list), f"Invalid requires value for {distribution}" for dep in data.get("requires", []): assert isinstance(dep, str), f"Invalid dependency {dep} for {distribution}" diff --git a/tests/check_new_syntax.py b/tests/check_new_syntax.py index fbe9f0f36..56e3bfc43 100755 --- a/tests/check_new_syntax.py +++ b/tests/check_new_syntax.py @@ -5,15 +5,10 @@ import sys from itertools import chain from pathlib import Path -STUBS_SUPPORTING_PYTHON_2 = frozenset( - path.parent for path in Path("stubs").rglob("METADATA.toml") if "python2 = true" in path.read_text().splitlines() -) - def check_new_syntax(tree: ast.AST, path: Path, stub: str) -> list[str]: errors = [] sourcelines = stub.splitlines() - python_2_support_required = any(directory in path.parents for directory in STUBS_SUPPORTING_PYTHON_2) class AnnotationUnionFinder(ast.NodeVisitor): def visit_Subscript(self, node: ast.Subscript) -> None: @@ -103,10 +98,9 @@ def check_new_syntax(tree: ast.AST, path: Path, stub: str) -> list[str]: ) self.generic_visit(node) - if not python_2_support_required: - ObjectClassdefFinder().visit(tree) - if path != Path("stdlib/typing_extensions.pyi"): - TextFinder().visit(tree) + ObjectClassdefFinder().visit(tree) + if path != Path("stdlib/typing_extensions.pyi"): + TextFinder().visit(tree) OldSyntaxFinder().visit(tree) IfFinder().visit(tree) diff --git a/tests/mypy_test.py b/tests/mypy_test.py index 66e1b1ebe..fede762df 100755 --- a/tests/mypy_test.py +++ b/tests/mypy_test.py @@ -15,7 +15,6 @@ import os import re import sys import tempfile -from glob import glob from pathlib import Path from typing import Dict, NamedTuple @@ -93,20 +92,6 @@ def parse_version(v_str): return int(m.group(1)), int(m.group(2)) -def is_supported(distribution_path: Path, major: int) -> bool: - data = dict(tomli.loads((distribution_path / "METADATA.toml").read_text())) - if major == 2: - # Python 2 is not supported by default. - return bool(data.get("python2", False)) - # Python 3 is supported by default. - return has_py3_stubs(distribution_path) - - -# Keep this in sync with stubtest_third_party.py -def has_py3_stubs(dist: Path) -> bool: - return len(glob(f"{dist}/*.pyi")) > 0 or len(glob(f"{dist}/[!@]*/__init__.pyi")) > 0 - - def add_files(files, seen, root, name, args): """Add all files in package or module represented by 'name' located in 'root'.""" full = os.path.join(root, name) @@ -326,22 +311,20 @@ def main(): files_checked += len(files) # Test files of all third party distributions. - print("Running mypy " + " ".join(get_mypy_flags(args, major, minor, "/tmp/..."))) - for distribution in sorted(os.listdir("stubs")): - if distribution == "SQLAlchemy": - continue # Crashes + if major != 2: + print("Running mypy " + " ".join(get_mypy_flags(args, major, minor, "/tmp/..."))) + for distribution in sorted(os.listdir("stubs")): + if distribution == "SQLAlchemy": + continue # Crashes - distribution_path = Path("stubs", distribution) + distribution_path = Path("stubs", distribution) - if not is_probably_stubs_folder(distribution, distribution_path): - continue + if not is_probably_stubs_folder(distribution, distribution_path): + continue - if not is_supported(distribution_path, major): - continue - - this_code, checked = test_third_party_distribution(distribution, major, minor, args) - code = max(code, this_code) - files_checked += checked + this_code, checked = test_third_party_distribution(distribution, major, minor, args) + code = max(code, this_code) + files_checked += checked print() diff --git a/tests/stubtest_third_party.py b/tests/stubtest_third_party.py index cf3848d9a..191f95cbf 100755 --- a/tests/stubtest_third_party.py +++ b/tests/stubtest_third_party.py @@ -9,9 +9,8 @@ import subprocess import sys import tempfile import venv -from glob import glob from pathlib import Path -from typing import Any, NoReturn +from typing import NoReturn import tomli @@ -26,7 +25,7 @@ def run_stubtest(dist: Path) -> bool: with open(dist / "METADATA.toml") as f: metadata = dict(tomli.loads(f.read())) - if not run_stubtest_for(metadata, dist): + if not metadata.get("stubtest", True): print(f"Skipping stubtest for {dist.name}\n\n") return True @@ -109,15 +108,6 @@ def run_stubtest(dist: Path) -> bool: return True -def run_stubtest_for(metadata: dict[str, Any], dist: Path) -> bool: - return has_py3_stubs(dist) and metadata.get("stubtest", True) - - -# Keep this in sync with mypy_test.py -def has_py3_stubs(dist: Path) -> bool: - return len(glob(f"{dist}/*.pyi")) > 0 or len(glob(f"{dist}/[!@]*/__init__.pyi")) > 0 - - def main() -> NoReturn: parser = argparse.ArgumentParser() parser.add_argument("--num-shards", type=int, default=1)