Skip to content

Commit 37b0182

Browse files
authored
Remove no longer needed Python 3.9 guards (#20321)
See #20154
1 parent a7e477f commit 37b0182

File tree

8 files changed

+52
-118
lines changed

8 files changed

+52
-118
lines changed

mypy/fastparse.py

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -149,28 +149,7 @@ def ast3_parse(
149149
)
150150

151151

152-
if sys.version_info >= (3, 10):
153-
Match = ast3.Match
154-
MatchValue = ast3.MatchValue
155-
MatchSingleton = ast3.MatchSingleton
156-
MatchSequence = ast3.MatchSequence
157-
MatchStar = ast3.MatchStar
158-
MatchMapping = ast3.MatchMapping
159-
MatchClass = ast3.MatchClass
160-
MatchAs = ast3.MatchAs
161-
MatchOr = ast3.MatchOr
162-
AstNode = Union[ast3.expr, ast3.stmt, ast3.pattern, ast3.ExceptHandler]
163-
else:
164-
Match = Any
165-
MatchValue = Any
166-
MatchSingleton = Any
167-
MatchSequence = Any
168-
MatchStar = Any
169-
MatchMapping = Any
170-
MatchClass = Any
171-
MatchAs = Any
172-
MatchOr = Any
173-
AstNode = Union[ast3.expr, ast3.stmt, ast3.ExceptHandler]
152+
AstNode = ast3.expr | ast3.stmt | ast3.pattern | ast3.ExceptHandler
174153

175154
if sys.version_info >= (3, 11):
176155
TryStar = ast3.TryStar
@@ -1779,7 +1758,7 @@ def visit_Slice(self, n: ast3.Slice) -> SliceExpr:
17791758
return self.set_line(e, n)
17801759

17811760
# Match(expr subject, match_case* cases) # python 3.10 and later
1782-
def visit_Match(self, n: Match) -> MatchStmt:
1761+
def visit_Match(self, n: ast3.Match) -> MatchStmt:
17831762
node = MatchStmt(
17841763
self.visit(n.subject),
17851764
[self.visit(c.pattern) for c in n.cases],
@@ -1788,23 +1767,23 @@ def visit_Match(self, n: Match) -> MatchStmt:
17881767
)
17891768
return self.set_line(node, n)
17901769

1791-
def visit_MatchValue(self, n: MatchValue) -> ValuePattern:
1770+
def visit_MatchValue(self, n: ast3.MatchValue) -> ValuePattern:
17921771
node = ValuePattern(self.visit(n.value))
17931772
return self.set_line(node, n)
17941773

1795-
def visit_MatchSingleton(self, n: MatchSingleton) -> SingletonPattern:
1774+
def visit_MatchSingleton(self, n: ast3.MatchSingleton) -> SingletonPattern:
17961775
node = SingletonPattern(n.value)
17971776
return self.set_line(node, n)
17981777

1799-
def visit_MatchSequence(self, n: MatchSequence) -> SequencePattern:
1778+
def visit_MatchSequence(self, n: ast3.MatchSequence) -> SequencePattern:
18001779
patterns = [self.visit(p) for p in n.patterns]
18011780
stars = [p for p in patterns if isinstance(p, StarredPattern)]
18021781
assert len(stars) < 2
18031782

18041783
node = SequencePattern(patterns)
18051784
return self.set_line(node, n)
18061785

1807-
def visit_MatchStar(self, n: MatchStar) -> StarredPattern:
1786+
def visit_MatchStar(self, n: ast3.MatchStar) -> StarredPattern:
18081787
if n.name is None:
18091788
node = StarredPattern(None)
18101789
else:
@@ -1813,7 +1792,7 @@ def visit_MatchStar(self, n: MatchStar) -> StarredPattern:
18131792

18141793
return self.set_line(node, n)
18151794

1816-
def visit_MatchMapping(self, n: MatchMapping) -> MappingPattern:
1795+
def visit_MatchMapping(self, n: ast3.MatchMapping) -> MappingPattern:
18171796
keys = [self.visit(k) for k in n.keys]
18181797
values = [self.visit(v) for v in n.patterns]
18191798

@@ -1825,7 +1804,7 @@ def visit_MatchMapping(self, n: MatchMapping) -> MappingPattern:
18251804
node = MappingPattern(keys, values, rest)
18261805
return self.set_line(node, n)
18271806

1828-
def visit_MatchClass(self, n: MatchClass) -> ClassPattern:
1807+
def visit_MatchClass(self, n: ast3.MatchClass) -> ClassPattern:
18291808
class_ref = self.visit(n.cls)
18301809
assert isinstance(class_ref, RefExpr)
18311810
positionals = [self.visit(p) for p in n.patterns]
@@ -1836,7 +1815,7 @@ def visit_MatchClass(self, n: MatchClass) -> ClassPattern:
18361815
return self.set_line(node, n)
18371816

18381817
# MatchAs(expr pattern, identifier name)
1839-
def visit_MatchAs(self, n: MatchAs) -> AsPattern:
1818+
def visit_MatchAs(self, n: ast3.MatchAs) -> AsPattern:
18401819
if n.name is None:
18411820
name = None
18421821
else:
@@ -1846,7 +1825,7 @@ def visit_MatchAs(self, n: MatchAs) -> AsPattern:
18461825
return self.set_line(node, n)
18471826

18481827
# MatchOr(expr* pattern)
1849-
def visit_MatchOr(self, n: MatchOr) -> OrPattern:
1828+
def visit_MatchOr(self, n: ast3.MatchOr) -> OrPattern:
18501829
node = OrPattern([self.visit(pattern) for pattern in n.patterns])
18511830
return self.set_line(node, n)
18521831

mypy/stubtest.py

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import typing_extensions
2727
import warnings
2828
from collections import defaultdict
29-
from collections.abc import Iterator, Set as AbstractSet
29+
from collections.abc import Iterator
3030
from contextlib import redirect_stderr, redirect_stdout
3131
from functools import singledispatch
3232
from pathlib import Path
@@ -2123,30 +2123,8 @@ def exists_in_version(module: str) -> bool:
21232123

21242124
def get_importable_stdlib_modules() -> set[str]:
21252125
"""Return all importable stdlib modules at runtime."""
2126-
all_stdlib_modules: AbstractSet[str]
2127-
if sys.version_info >= (3, 10):
2128-
all_stdlib_modules = sys.stdlib_module_names
2129-
else:
2130-
all_stdlib_modules = set(sys.builtin_module_names)
2131-
modules_by_finder: defaultdict[importlib.machinery.FileFinder, set[str]] = defaultdict(set)
2132-
for m in pkgutil.iter_modules():
2133-
if isinstance(m.module_finder, importlib.machinery.FileFinder):
2134-
modules_by_finder[m.module_finder].add(m.name)
2135-
for finder, module_group in modules_by_finder.items():
2136-
if (
2137-
"site-packages" not in Path(finder.path).parts
2138-
# if "_queue" is present, it's most likely the module finder
2139-
# for stdlib extension modules;
2140-
# if "queue" is present, it's most likely the module finder
2141-
# for pure-Python stdlib modules.
2142-
# In either case, we'll want to add all the modules that the finder has to offer us.
2143-
# This is a bit hacky, but seems to work well in a cross-platform way.
2144-
and {"_queue", "queue"} & module_group
2145-
):
2146-
all_stdlib_modules.update(module_group)
2147-
21482126
importable_stdlib_modules: set[str] = set()
2149-
for module_name in all_stdlib_modules:
2127+
for module_name in sys.stdlib_module_names:
21502128
if module_name in ANNOYING_STDLIB_MODULES:
21512129
continue
21522130

mypy/test/testcheck.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838
typecheck_files = find_test_files(pattern="check-*.test")
3939

4040
# Tests that use Python version specific features:
41-
if sys.version_info < (3, 10):
42-
typecheck_files.remove("check-python310.test")
4341
if sys.version_info < (3, 11):
4442
typecheck_files.remove("check-python311.test")
4543
if sys.version_info < (3, 12):

mypy/test/testparse.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ class ParserSuite(DataSuite):
2121
base_path = "."
2222
files = find_test_files(pattern="parse*.test", exclude=["parse-errors.test"])
2323

24-
if sys.version_info < (3, 10):
25-
files.remove("parse-python310.test")
2624
if sys.version_info < (3, 12):
2725
files.remove("parse-python312.test")
2826
if sys.version_info < (3, 13):

mypy/test/testsemanal.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
from __future__ import annotations
44

5-
import sys
6-
75
from mypy import build
86
from mypy.defaults import PYTHON3_VERSION
97
from mypy.errors import CompileError
@@ -26,18 +24,14 @@
2624
semanal_files = find_test_files(
2725
pattern="semanal-*.test",
2826
exclude=[
29-
"semanal-errors-python310.test",
3027
"semanal-errors.test",
28+
"semanal-errors-python310.test",
3129
"semanal-typeinfo.test",
3230
"semanal-symtable.test",
3331
],
3432
)
3533

3634

37-
if sys.version_info < (3, 10):
38-
semanal_files.remove("semanal-python310.test")
39-
40-
4135
def get_semanal_options(program_text: str, testcase: DataDrivenTestCase) -> Options:
4236
options = parse_options(program_text, testcase, 1)
4337
options.use_builtins_fixtures = True
@@ -92,9 +86,7 @@ def test_semanal(testcase: DataDrivenTestCase) -> None:
9286

9387

9488
class SemAnalErrorSuite(DataSuite):
95-
files = ["semanal-errors.test"]
96-
if sys.version_info >= (3, 10):
97-
semanal_files.append("semanal-errors-python310.test")
89+
files = ["semanal-errors.test", "semanal-errors-python310.test"]
9890

9991
def run_case(self, testcase: DataDrivenTestCase) -> None:
10092
test_semanal_error(testcase)

mypy/test/teststubtest.py

Lines changed: 36 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,38 +1306,37 @@ def fizz(self): pass
13061306
""",
13071307
error=None,
13081308
)
1309-
if sys.version_info >= (3, 10):
1310-
yield Case(
1311-
stub="""
1312-
Q = Dict[str, str]
1313-
R = dict[int, int]
1314-
S = Tuple[int, int]
1315-
T = tuple[str, str]
1316-
U = int | str
1317-
V = Union[int, str]
1318-
W = typing.Callable[[str], bool]
1319-
Z = collections.abc.Callable[[str], bool]
1320-
QQ = typing.Iterable[str]
1321-
RR = collections.abc.Iterable[str]
1322-
MM = typing.Match[str]
1323-
MMM = re.Match[str]
1324-
""",
1325-
runtime="""
1326-
Q = dict[str, str]
1327-
R = dict[int, int]
1328-
S = tuple[int, int]
1329-
T = tuple[str, str]
1330-
U = int | str
1331-
V = int | str
1332-
W = collections.abc.Callable[[str], bool]
1333-
Z = collections.abc.Callable[[str], bool]
1334-
QQ = collections.abc.Iterable[str]
1335-
RR = collections.abc.Iterable[str]
1336-
MM = re.Match[str]
1337-
MMM = re.Match[str]
1338-
""",
1339-
error=None,
1340-
)
1309+
yield Case(
1310+
stub="""
1311+
Q = Dict[str, str]
1312+
R = dict[int, int]
1313+
S = Tuple[int, int]
1314+
T = tuple[str, str]
1315+
U = int | str
1316+
V = Union[int, str]
1317+
W = typing.Callable[[str], bool]
1318+
Z = collections.abc.Callable[[str], bool]
1319+
QQ = typing.Iterable[str]
1320+
RR = collections.abc.Iterable[str]
1321+
MM = typing.Match[str]
1322+
MMM = re.Match[str]
1323+
""",
1324+
runtime="""
1325+
Q = dict[str, str]
1326+
R = dict[int, int]
1327+
S = tuple[int, int]
1328+
T = tuple[str, str]
1329+
U = int | str
1330+
V = int | str
1331+
W = collections.abc.Callable[[str], bool]
1332+
Z = collections.abc.Callable[[str], bool]
1333+
QQ = collections.abc.Iterable[str]
1334+
RR = collections.abc.Iterable[str]
1335+
MM = re.Match[str]
1336+
MMM = re.Match[str]
1337+
""",
1338+
error=None,
1339+
)
13411340

13421341
@collect_cases
13431342
def test_enum(self) -> Iterator[Case]:
@@ -2356,13 +2355,10 @@ def test_type_var(self) -> Iterator[Case]:
23562355
)
23572356
yield Case(stub="A = TypeVar('A')", runtime="A = TypeVar('A')", error=None)
23582357
yield Case(stub="B = TypeVar('B')", runtime="B = 5", error="B")
2359-
if sys.version_info >= (3, 10):
2360-
yield Case(
2361-
stub="from typing import ParamSpec",
2362-
runtime="from typing import ParamSpec",
2363-
error=None,
2364-
)
2365-
yield Case(stub="C = ParamSpec('C')", runtime="C = ParamSpec('C')", error=None)
2358+
yield Case(
2359+
stub="from typing import ParamSpec", runtime="from typing import ParamSpec", error=None
2360+
)
2361+
yield Case(stub="C = ParamSpec('C')", runtime="C = ParamSpec('C')", error=None)
23662362

23672363
@collect_cases
23682364
def test_metaclass_match(self) -> Iterator[Case]:
@@ -2886,10 +2882,7 @@ def myfunction(arg: str, /) -> None: ...
28862882
stub = result.files["__main__"].names["myfunction"].node
28872883
assert isinstance(stub, nodes.OverloadedFuncDef)
28882884
sig = mypy.stubtest.Signature.from_overloadedfuncdef(stub)
2889-
if sys.version_info >= (3, 10):
2890-
assert str(sig) == "def (arg: builtins.int | builtins.str)"
2891-
else:
2892-
assert str(sig) == "def (arg: Union[builtins.int, builtins.str])"
2885+
assert str(sig) == "def (arg: builtins.int | builtins.str)"
28932886

28942887
def test_config_file(self) -> None:
28952888
runtime = "temp = 5\n"

mypyc/test/test_irbuild.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from __future__ import annotations
44

55
import os.path
6-
import sys
76

87
from mypy.errors import CompileError
98
from mypy.test.config import test_temp_dir
@@ -56,11 +55,9 @@
5655
"irbuild-weakref.test",
5756
"irbuild-librt-strings.test",
5857
"irbuild-base64.test",
58+
"irbuild-match.test",
5959
]
6060

61-
if sys.version_info >= (3, 10):
62-
files.append("irbuild-match.test")
63-
6461

6562
class TestGenOps(MypycDataSuite):
6663
files = files

mypyc/test/test_run.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,9 @@
7575
"run-python38.test",
7676
"run-librt-strings.test",
7777
"run-base64.test",
78+
"run-match.test",
7879
]
7980

80-
if sys.version_info >= (3, 10):
81-
files.append("run-match.test")
8281
if sys.version_info >= (3, 12):
8382
files.append("run-python312.test")
8483

0 commit comments

Comments
 (0)