mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-07 04:34:28 +08:00
Drop Python 2 support in third-party stubs (#7703)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
version = "1.2.*"
|
||||
python2 = true
|
||||
requires = []
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
version = "3.7.*"
|
||||
python2 = true
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
version = "2021.10.8"
|
||||
python2 = true
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
version = "14.3.*"
|
||||
python2 = true
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
version = "0.4.*"
|
||||
python2 = true
|
||||
@@ -1,3 +1,2 @@
|
||||
# Prior to v0.6, docopt() had only 3 optional args
|
||||
version = "0.6.*"
|
||||
python2 = true
|
||||
@@ -1,2 +1 @@
|
||||
version = "2.0.*"
|
||||
python2 = true
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
version = "0.4.*"
|
||||
python2 = true
|
||||
|
||||
@@ -1,3 +1,2 @@
|
||||
version = "0.2.*"
|
||||
python2 = true
|
||||
stubtest_apt_dependencies = ["portaudio19-dev"]
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
version = "2021.3"
|
||||
python2 = true
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
version = "0.9.*"
|
||||
python2 = true
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
version = "3.7.*"
|
||||
python2 = true
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
version = "0.8.*"
|
||||
python2 = true
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
version = "2.0.*"
|
||||
python2 = true
|
||||
|
||||
@@ -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}"
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user