diff --git a/mypy/fastparse.py b/mypy/fastparse.py index 0e7b418d0375..1b7a42453183 100644 --- a/mypy/fastparse.py +++ b/mypy/fastparse.py @@ -149,28 +149,7 @@ def ast3_parse( ) -if sys.version_info >= (3, 10): - Match = ast3.Match - MatchValue = ast3.MatchValue - MatchSingleton = ast3.MatchSingleton - MatchSequence = ast3.MatchSequence - MatchStar = ast3.MatchStar - MatchMapping = ast3.MatchMapping - MatchClass = ast3.MatchClass - MatchAs = ast3.MatchAs - MatchOr = ast3.MatchOr - AstNode = Union[ast3.expr, ast3.stmt, ast3.pattern, ast3.ExceptHandler] -else: - Match = Any - MatchValue = Any - MatchSingleton = Any - MatchSequence = Any - MatchStar = Any - MatchMapping = Any - MatchClass = Any - MatchAs = Any - MatchOr = Any - AstNode = Union[ast3.expr, ast3.stmt, ast3.ExceptHandler] +AstNode = ast3.expr | ast3.stmt | ast3.pattern | ast3.ExceptHandler if sys.version_info >= (3, 11): TryStar = ast3.TryStar @@ -1781,7 +1760,7 @@ def visit_Slice(self, n: ast3.Slice) -> SliceExpr: return self.set_line(e, n) # Match(expr subject, match_case* cases) # python 3.10 and later - def visit_Match(self, n: Match) -> MatchStmt: + def visit_Match(self, n: ast3.Match) -> MatchStmt: node = MatchStmt( self.visit(n.subject), [self.visit(c.pattern) for c in n.cases], @@ -1790,15 +1769,15 @@ def visit_Match(self, n: Match) -> MatchStmt: ) return self.set_line(node, n) - def visit_MatchValue(self, n: MatchValue) -> ValuePattern: + def visit_MatchValue(self, n: ast3.MatchValue) -> ValuePattern: node = ValuePattern(self.visit(n.value)) return self.set_line(node, n) - def visit_MatchSingleton(self, n: MatchSingleton) -> SingletonPattern: + def visit_MatchSingleton(self, n: ast3.MatchSingleton) -> SingletonPattern: node = SingletonPattern(n.value) return self.set_line(node, n) - def visit_MatchSequence(self, n: MatchSequence) -> SequencePattern: + def visit_MatchSequence(self, n: ast3.MatchSequence) -> SequencePattern: patterns = [self.visit(p) for p in n.patterns] stars = [p for p in patterns if isinstance(p, StarredPattern)] assert len(stars) < 2 @@ -1806,7 +1785,7 @@ def visit_MatchSequence(self, n: MatchSequence) -> SequencePattern: node = SequencePattern(patterns) return self.set_line(node, n) - def visit_MatchStar(self, n: MatchStar) -> StarredPattern: + def visit_MatchStar(self, n: ast3.MatchStar) -> StarredPattern: if n.name is None: node = StarredPattern(None) else: @@ -1815,7 +1794,7 @@ def visit_MatchStar(self, n: MatchStar) -> StarredPattern: return self.set_line(node, n) - def visit_MatchMapping(self, n: MatchMapping) -> MappingPattern: + def visit_MatchMapping(self, n: ast3.MatchMapping) -> MappingPattern: keys = [self.visit(k) for k in n.keys] values = [self.visit(v) for v in n.patterns] @@ -1827,7 +1806,7 @@ def visit_MatchMapping(self, n: MatchMapping) -> MappingPattern: node = MappingPattern(keys, values, rest) return self.set_line(node, n) - def visit_MatchClass(self, n: MatchClass) -> ClassPattern: + def visit_MatchClass(self, n: ast3.MatchClass) -> ClassPattern: class_ref = self.visit(n.cls) assert isinstance(class_ref, RefExpr) positionals = [self.visit(p) for p in n.patterns] @@ -1838,7 +1817,7 @@ def visit_MatchClass(self, n: MatchClass) -> ClassPattern: return self.set_line(node, n) # MatchAs(expr pattern, identifier name) - def visit_MatchAs(self, n: MatchAs) -> AsPattern: + def visit_MatchAs(self, n: ast3.MatchAs) -> AsPattern: if n.name is None: name = None else: @@ -1848,7 +1827,7 @@ def visit_MatchAs(self, n: MatchAs) -> AsPattern: return self.set_line(node, n) # MatchOr(expr* pattern) - def visit_MatchOr(self, n: MatchOr) -> OrPattern: + def visit_MatchOr(self, n: ast3.MatchOr) -> OrPattern: node = OrPattern([self.visit(pattern) for pattern in n.patterns]) return self.set_line(node, n) diff --git a/mypy/stubtest.py b/mypy/stubtest.py index ada56a2489fe..4995da75ab7d 100644 --- a/mypy/stubtest.py +++ b/mypy/stubtest.py @@ -26,7 +26,7 @@ import typing_extensions import warnings from collections import defaultdict -from collections.abc import Iterator, Set as AbstractSet +from collections.abc import Iterator from contextlib import redirect_stderr, redirect_stdout from functools import singledispatch from pathlib import Path @@ -2123,30 +2123,8 @@ def exists_in_version(module: str) -> bool: def get_importable_stdlib_modules() -> set[str]: """Return all importable stdlib modules at runtime.""" - all_stdlib_modules: AbstractSet[str] - if sys.version_info >= (3, 10): - all_stdlib_modules = sys.stdlib_module_names - else: - all_stdlib_modules = set(sys.builtin_module_names) - modules_by_finder: defaultdict[importlib.machinery.FileFinder, set[str]] = defaultdict(set) - for m in pkgutil.iter_modules(): - if isinstance(m.module_finder, importlib.machinery.FileFinder): - modules_by_finder[m.module_finder].add(m.name) - for finder, module_group in modules_by_finder.items(): - if ( - "site-packages" not in Path(finder.path).parts - # if "_queue" is present, it's most likely the module finder - # for stdlib extension modules; - # if "queue" is present, it's most likely the module finder - # for pure-Python stdlib modules. - # In either case, we'll want to add all the modules that the finder has to offer us. - # This is a bit hacky, but seems to work well in a cross-platform way. - and {"_queue", "queue"} & module_group - ): - all_stdlib_modules.update(module_group) - importable_stdlib_modules: set[str] = set() - for module_name in all_stdlib_modules: + for module_name in sys.stdlib_module_names: if module_name in ANNOYING_STDLIB_MODULES: continue diff --git a/mypy/test/testcheck.py b/mypy/test/testcheck.py index f2b7057d9f20..05c3bce51a2f 100644 --- a/mypy/test/testcheck.py +++ b/mypy/test/testcheck.py @@ -38,8 +38,6 @@ typecheck_files = find_test_files(pattern="check-*.test") # Tests that use Python version specific features: -if sys.version_info < (3, 10): - typecheck_files.remove("check-python310.test") if sys.version_info < (3, 11): typecheck_files.remove("check-python311.test") if sys.version_info < (3, 12): diff --git a/mypy/test/testparse.py b/mypy/test/testparse.py index c8bcb5c0d807..d9d94a5edc38 100644 --- a/mypy/test/testparse.py +++ b/mypy/test/testparse.py @@ -21,8 +21,6 @@ class ParserSuite(DataSuite): base_path = "." files = find_test_files(pattern="parse*.test", exclude=["parse-errors.test"]) - if sys.version_info < (3, 10): - files.remove("parse-python310.test") if sys.version_info < (3, 12): files.remove("parse-python312.test") if sys.version_info < (3, 13): diff --git a/mypy/test/testsemanal.py b/mypy/test/testsemanal.py index 741c03fc2dc2..11cd36c83fd7 100644 --- a/mypy/test/testsemanal.py +++ b/mypy/test/testsemanal.py @@ -2,8 +2,6 @@ from __future__ import annotations -import sys - from mypy import build from mypy.defaults import PYTHON3_VERSION from mypy.errors import CompileError @@ -26,18 +24,14 @@ semanal_files = find_test_files( pattern="semanal-*.test", exclude=[ - "semanal-errors-python310.test", "semanal-errors.test", + "semanal-errors-python310.test", "semanal-typeinfo.test", "semanal-symtable.test", ], ) -if sys.version_info < (3, 10): - semanal_files.remove("semanal-python310.test") - - def get_semanal_options(program_text: str, testcase: DataDrivenTestCase) -> Options: options = parse_options(program_text, testcase, 1) options.use_builtins_fixtures = True @@ -92,9 +86,7 @@ def test_semanal(testcase: DataDrivenTestCase) -> None: class SemAnalErrorSuite(DataSuite): - files = ["semanal-errors.test"] - if sys.version_info >= (3, 10): - semanal_files.append("semanal-errors-python310.test") + files = ["semanal-errors.test", "semanal-errors-python310.test"] def run_case(self, testcase: DataDrivenTestCase) -> None: test_semanal_error(testcase) diff --git a/mypy/test/teststubtest.py b/mypy/test/teststubtest.py index 4bec5daf3ffb..5435b45b4689 100644 --- a/mypy/test/teststubtest.py +++ b/mypy/test/teststubtest.py @@ -1306,38 +1306,37 @@ def fizz(self): pass """, error=None, ) - if sys.version_info >= (3, 10): - yield Case( - stub=""" - Q = Dict[str, str] - R = dict[int, int] - S = Tuple[int, int] - T = tuple[str, str] - U = int | str - V = Union[int, str] - W = typing.Callable[[str], bool] - Z = collections.abc.Callable[[str], bool] - QQ = typing.Iterable[str] - RR = collections.abc.Iterable[str] - MM = typing.Match[str] - MMM = re.Match[str] - """, - runtime=""" - Q = dict[str, str] - R = dict[int, int] - S = tuple[int, int] - T = tuple[str, str] - U = int | str - V = int | str - W = collections.abc.Callable[[str], bool] - Z = collections.abc.Callable[[str], bool] - QQ = collections.abc.Iterable[str] - RR = collections.abc.Iterable[str] - MM = re.Match[str] - MMM = re.Match[str] - """, - error=None, - ) + yield Case( + stub=""" + Q = Dict[str, str] + R = dict[int, int] + S = Tuple[int, int] + T = tuple[str, str] + U = int | str + V = Union[int, str] + W = typing.Callable[[str], bool] + Z = collections.abc.Callable[[str], bool] + QQ = typing.Iterable[str] + RR = collections.abc.Iterable[str] + MM = typing.Match[str] + MMM = re.Match[str] + """, + runtime=""" + Q = dict[str, str] + R = dict[int, int] + S = tuple[int, int] + T = tuple[str, str] + U = int | str + V = int | str + W = collections.abc.Callable[[str], bool] + Z = collections.abc.Callable[[str], bool] + QQ = collections.abc.Iterable[str] + RR = collections.abc.Iterable[str] + MM = re.Match[str] + MMM = re.Match[str] + """, + error=None, + ) @collect_cases def test_enum(self) -> Iterator[Case]: @@ -2356,13 +2355,10 @@ def test_type_var(self) -> Iterator[Case]: ) yield Case(stub="A = TypeVar('A')", runtime="A = TypeVar('A')", error=None) yield Case(stub="B = TypeVar('B')", runtime="B = 5", error="B") - if sys.version_info >= (3, 10): - yield Case( - stub="from typing import ParamSpec", - runtime="from typing import ParamSpec", - error=None, - ) - yield Case(stub="C = ParamSpec('C')", runtime="C = ParamSpec('C')", error=None) + yield Case( + stub="from typing import ParamSpec", runtime="from typing import ParamSpec", error=None + ) + yield Case(stub="C = ParamSpec('C')", runtime="C = ParamSpec('C')", error=None) @collect_cases def test_metaclass_match(self) -> Iterator[Case]: @@ -2886,10 +2882,7 @@ def myfunction(arg: str, /) -> None: ... stub = result.files["__main__"].names["myfunction"].node assert isinstance(stub, nodes.OverloadedFuncDef) sig = mypy.stubtest.Signature.from_overloadedfuncdef(stub) - if sys.version_info >= (3, 10): - assert str(sig) == "def (arg: builtins.int | builtins.str)" - else: - assert str(sig) == "def (arg: Union[builtins.int, builtins.str])" + assert str(sig) == "def (arg: builtins.int | builtins.str)" def test_config_file(self) -> None: runtime = "temp = 5\n" diff --git a/mypyc/test/test_irbuild.py b/mypyc/test/test_irbuild.py index b0ede4569164..707ee1142862 100644 --- a/mypyc/test/test_irbuild.py +++ b/mypyc/test/test_irbuild.py @@ -3,7 +3,6 @@ from __future__ import annotations import os.path -import sys from mypy.errors import CompileError from mypy.test.config import test_temp_dir @@ -56,11 +55,9 @@ "irbuild-weakref.test", "irbuild-librt-strings.test", "irbuild-base64.test", + "irbuild-match.test", ] -if sys.version_info >= (3, 10): - files.append("irbuild-match.test") - class TestGenOps(MypycDataSuite): files = files diff --git a/mypyc/test/test_run.py b/mypyc/test/test_run.py index 27f7674d68c8..d332a7466af4 100644 --- a/mypyc/test/test_run.py +++ b/mypyc/test/test_run.py @@ -75,10 +75,9 @@ "run-python38.test", "run-librt-strings.test", "run-base64.test", + "run-match.test", ] -if sys.version_info >= (3, 10): - files.append("run-match.test") if sys.version_info >= (3, 12): files.append("run-python312.test")