Skip to content

Commit f4e6a01

Browse files
committed
Remove no longer needed Python 3.9 guards
1 parent 1a6ff59 commit f4e6a01

File tree

8 files changed

+51
-112
lines changed

8 files changed

+51
-112
lines changed

mypy/fastparse.py

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -149,29 +149,6 @@ 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]
174-
175152
if sys.version_info >= (3, 11):
176153
TryStar = ast3.TryStar
177154
else:
@@ -444,7 +421,7 @@ def visit(self, node: AST | None) -> Any:
444421

445422
return visitor(node)
446423

447-
def set_line(self, node: N, n: AstNode) -> N:
424+
def set_line(self, node: N, n: ast3.expr | ast3.stmt | ast3.pattern | ast3.ExceptHandler) -> N:
448425
node.line = n.lineno
449426
node.column = n.col_offset
450427
node.end_line = getattr(n, "end_lineno", None)
@@ -1781,7 +1758,7 @@ def visit_Slice(self, n: ast3.Slice) -> SliceExpr:
17811758
return self.set_line(e, n)
17821759

17831760
# Match(expr subject, match_case* cases) # python 3.10 and later
1784-
def visit_Match(self, n: Match) -> MatchStmt:
1761+
def visit_Match(self, n: ast3.Match) -> MatchStmt:
17851762
node = MatchStmt(
17861763
self.visit(n.subject),
17871764
[self.visit(c.pattern) for c in n.cases],
@@ -1790,23 +1767,23 @@ def visit_Match(self, n: Match) -> MatchStmt:
17901767
)
17911768
return self.set_line(node, n)
17921769

1793-
def visit_MatchValue(self, n: MatchValue) -> ValuePattern:
1770+
def visit_MatchValue(self, n: ast3.MatchValue) -> ValuePattern:
17941771
node = ValuePattern(self.visit(n.value))
17951772
return self.set_line(node, n)
17961773

1797-
def visit_MatchSingleton(self, n: MatchSingleton) -> SingletonPattern:
1774+
def visit_MatchSingleton(self, n: ast3.MatchSingleton) -> SingletonPattern:
17981775
node = SingletonPattern(n.value)
17991776
return self.set_line(node, n)
18001777

1801-
def visit_MatchSequence(self, n: MatchSequence) -> SequencePattern:
1778+
def visit_MatchSequence(self, n: ast3.MatchSequence) -> SequencePattern:
18021779
patterns = [self.visit(p) for p in n.patterns]
18031780
stars = [p for p in patterns if isinstance(p, StarredPattern)]
18041781
assert len(stars) < 2
18051782

18061783
node = SequencePattern(patterns)
18071784
return self.set_line(node, n)
18081785

1809-
def visit_MatchStar(self, n: MatchStar) -> StarredPattern:
1786+
def visit_MatchStar(self, n: ast3.MatchStar) -> StarredPattern:
18101787
if n.name is None:
18111788
node = StarredPattern(None)
18121789
else:
@@ -1815,7 +1792,7 @@ def visit_MatchStar(self, n: MatchStar) -> StarredPattern:
18151792

18161793
return self.set_line(node, n)
18171794

1818-
def visit_MatchMapping(self, n: MatchMapping) -> MappingPattern:
1795+
def visit_MatchMapping(self, n: ast3.MatchMapping) -> MappingPattern:
18191796
keys = [self.visit(k) for k in n.keys]
18201797
values = [self.visit(v) for v in n.patterns]
18211798

@@ -1827,7 +1804,7 @@ def visit_MatchMapping(self, n: MatchMapping) -> MappingPattern:
18271804
node = MappingPattern(keys, values, rest)
18281805
return self.set_line(node, n)
18291806

1830-
def visit_MatchClass(self, n: MatchClass) -> ClassPattern:
1807+
def visit_MatchClass(self, n: ast3.MatchClass) -> ClassPattern:
18311808
class_ref = self.visit(n.cls)
18321809
assert isinstance(class_ref, RefExpr)
18331810
positionals = [self.visit(p) for p in n.patterns]
@@ -1838,7 +1815,7 @@ def visit_MatchClass(self, n: MatchClass) -> ClassPattern:
18381815
return self.set_line(node, n)
18391816

18401817
# MatchAs(expr pattern, identifier name)
1841-
def visit_MatchAs(self, n: MatchAs) -> AsPattern:
1818+
def visit_MatchAs(self, n: ast3.MatchAs) -> AsPattern:
18421819
if n.name is None:
18431820
name = None
18441821
else:
@@ -1848,7 +1825,7 @@ def visit_MatchAs(self, n: MatchAs) -> AsPattern:
18481825
return self.set_line(node, n)
18491826

18501827
# MatchOr(expr* pattern)
1851-
def visit_MatchOr(self, n: MatchOr) -> OrPattern:
1828+
def visit_MatchOr(self, n: ast3.MatchOr) -> OrPattern:
18521829
node = OrPattern([self.visit(pattern) for pattern in n.patterns])
18531830
return self.set_line(node, n)
18541831

mypy/stubtest.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2124,26 +2124,7 @@ def exists_in_version(module: str) -> bool:
21242124
def get_importable_stdlib_modules() -> set[str]:
21252125
"""Return all importable stdlib modules at runtime."""
21262126
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)
2127+
all_stdlib_modules = sys.stdlib_module_names
21472128

21482129
importable_stdlib_modules: set[str] = set()
21492130
for module_name in all_stdlib_modules:

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: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,13 @@
2626
semanal_files = find_test_files(
2727
pattern="semanal-*.test",
2828
exclude=[
29-
"semanal-errors-python310.test",
3029
"semanal-errors.test",
3130
"semanal-typeinfo.test",
3231
"semanal-symtable.test",
3332
],
3433
)
3534

3635

37-
if sys.version_info < (3, 10):
38-
semanal_files.remove("semanal-python310.test")
39-
40-
4136
def get_semanal_options(program_text: str, testcase: DataDrivenTestCase) -> Options:
4237
options = parse_options(program_text, testcase, 1)
4338
options.use_builtins_fixtures = True
@@ -93,8 +88,6 @@ def test_semanal(testcase: DataDrivenTestCase) -> None:
9388

9489
class SemAnalErrorSuite(DataSuite):
9590
files = ["semanal-errors.test"]
96-
if sys.version_info >= (3, 10):
97-
semanal_files.append("semanal-errors-python310.test")
9891

9992
def run_case(self, testcase: DataDrivenTestCase) -> None:
10093
test_semanal_error(testcase)

mypy/test/teststubtest.py

Lines changed: 38 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,12 @@ 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",
2360+
runtime="from typing import ParamSpec",
2361+
error=None,
2362+
)
2363+
yield Case(stub="C = ParamSpec('C')", runtime="C = ParamSpec('C')", error=None)
23662364

23672365
@collect_cases
23682366
def test_metaclass_match(self) -> Iterator[Case]:
@@ -2886,10 +2884,7 @@ def myfunction(arg: str, /) -> None: ...
28862884
stub = result.files["__main__"].names["myfunction"].node
28872885
assert isinstance(stub, nodes.OverloadedFuncDef)
28882886
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])"
2887+
assert str(sig) == "def (arg: builtins.int | builtins.str)"
28932888

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

mypyc/test/test_irbuild.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,9 @@
5656
"irbuild-weakref.test",
5757
"irbuild-librt-strings.test",
5858
"irbuild-base64.test",
59+
"irbuild-match.test",
5960
]
6061

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

6563
class TestGenOps(MypycDataSuite):
6664
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)