Skip to content

Commit b1f4763

Browse files
committed
Remove version guards
1 parent a1e282e commit b1f4763

File tree

8 files changed

+64
-112
lines changed

8 files changed

+64
-112
lines changed

mypy/fastparse.py

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,28 @@
129129
PY_MINOR_VERSION: Final = sys.version_info[1]
130130

131131
import ast as ast3
132-
from ast import AST, Attribute, Call, FunctionType, Name, Starred, UAdd, UnaryOp, USub
132+
from ast import (
133+
AST,
134+
Attribute,
135+
Call,
136+
Constant,
137+
FunctionType,
138+
Match,
139+
MatchAs,
140+
MatchClass,
141+
MatchMapping,
142+
MatchOr,
143+
MatchSequence,
144+
MatchSingleton,
145+
MatchStar,
146+
MatchValue,
147+
Name,
148+
NamedExpr,
149+
Starred,
150+
UAdd,
151+
UnaryOp,
152+
USub,
153+
)
133154

134155

135156
def ast3_parse(
@@ -144,31 +165,7 @@ def ast3_parse(
144165
)
145166

146167

147-
NamedExpr = ast3.NamedExpr
148-
Constant = ast3.Constant
149-
150-
if sys.version_info >= (3, 10):
151-
Match = ast3.Match
152-
MatchValue = ast3.MatchValue
153-
MatchSingleton = ast3.MatchSingleton
154-
MatchSequence = ast3.MatchSequence
155-
MatchStar = ast3.MatchStar
156-
MatchMapping = ast3.MatchMapping
157-
MatchClass = ast3.MatchClass
158-
MatchAs = ast3.MatchAs
159-
MatchOr = ast3.MatchOr
160-
AstNode = ast3.expr | ast3.stmt | ast3.pattern | ast3.ExceptHandler
161-
else:
162-
Match = Any
163-
MatchValue = Any
164-
MatchSingleton = Any
165-
MatchSequence = Any
166-
MatchStar = Any
167-
MatchMapping = Any
168-
MatchClass = Any
169-
MatchAs = Any
170-
MatchOr = Any
171-
AstNode = ast3.expr | ast3.stmt | ast3.ExceptHandler
168+
AstNode = ast3.expr | ast3.stmt | ast3.pattern | ast3.ExceptHandler
172169

173170
if sys.version_info >= (3, 11):
174171
TryStar = ast3.TryStar

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
@@ -2111,30 +2111,8 @@ def exists_in_version(module: str) -> bool:
21112111

21122112
def get_importable_stdlib_modules() -> set[str]:
21132113
"""Return all importable stdlib modules at runtime."""
2114-
all_stdlib_modules: AbstractSet[str]
2115-
if sys.version_info >= (3, 10):
2116-
all_stdlib_modules = sys.stdlib_module_names
2117-
else:
2118-
all_stdlib_modules = set(sys.builtin_module_names)
2119-
modules_by_finder: defaultdict[importlib.machinery.FileFinder, set[str]] = defaultdict(set)
2120-
for m in pkgutil.iter_modules():
2121-
if isinstance(m.module_finder, importlib.machinery.FileFinder):
2122-
modules_by_finder[m.module_finder].add(m.name)
2123-
for finder, module_group in modules_by_finder.items():
2124-
if (
2125-
"site-packages" not in Path(finder.path).parts
2126-
# if "_queue" is present, it's most likely the module finder
2127-
# for stdlib extension modules;
2128-
# if "queue" is present, it's most likely the module finder
2129-
# for pure-Python stdlib modules.
2130-
# In either case, we'll want to add all the modules that the finder has to offer us.
2131-
# This is a bit hacky, but seems to work well in a cross-platform way.
2132-
and {"_queue", "queue"} & module_group
2133-
):
2134-
all_stdlib_modules.update(module_group)
2135-
21362114
importable_stdlib_modules: set[str] = set()
2137-
for module_name in all_stdlib_modules:
2115+
for module_name in sys.stdlib_module_names:
21382116
if module_name in ANNOYING_STDLIB_MODULES:
21392117
continue
21402118

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: 1 addition & 9 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
@@ -34,10 +32,6 @@
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]:
@@ -2332,13 +2331,10 @@ def test_type_var(self) -> Iterator[Case]:
23322331
)
23332332
yield Case(stub="A = TypeVar('A')", runtime="A = TypeVar('A')", error=None)
23342333
yield Case(stub="B = TypeVar('B')", runtime="B = 5", error="B")
2335-
if sys.version_info >= (3, 10):
2336-
yield Case(
2337-
stub="from typing import ParamSpec",
2338-
runtime="from typing import ParamSpec",
2339-
error=None,
2340-
)
2341-
yield Case(stub="C = ParamSpec('C')", runtime="C = ParamSpec('C')", error=None)
2334+
yield Case(
2335+
stub="from typing import ParamSpec", runtime="from typing import ParamSpec", error=None
2336+
)
2337+
yield Case(stub="C = ParamSpec('C')", runtime="C = ParamSpec('C')", error=None)
23422338

23432339
@collect_cases
23442340
def test_metaclass_match(self) -> Iterator[Case]:
@@ -2862,10 +2858,7 @@ def myfunction(arg: str, /) -> None: ...
28622858
stub = result.files["__main__"].names["myfunction"].node
28632859
assert isinstance(stub, nodes.OverloadedFuncDef)
28642860
sig = mypy.stubtest.Signature.from_overloadedfuncdef(stub)
2865-
if sys.version_info >= (3, 10):
2866-
assert str(sig) == "def (arg: builtins.int | builtins.str)"
2867-
else:
2868-
assert str(sig) == "def (arg: Union[builtins.int, builtins.str])"
2861+
assert str(sig) == "def (arg: builtins.int | builtins.str)"
28692862

28702863
def test_config_file(self) -> None:
28712864
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
@@ -54,11 +53,9 @@
5453
"irbuild-glue-methods.test",
5554
"irbuild-math.test",
5655
"irbuild-weakref.test",
56+
"irbuild-match.test",
5757
]
5858

59-
if sys.version_info >= (3, 10):
60-
files.append("irbuild-match.test")
61-
6259

6360
class TestGenOps(MypycDataSuite):
6461
files = files

mypyc/test/test_run.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,9 @@
7373
"run-weakref.test",
7474
"run-python37.test",
7575
"run-python38.test",
76+
"run-match.test",
7677
]
7778

78-
if sys.version_info >= (3, 10):
79-
files.append("run-match.test")
8079
if sys.version_info >= (3, 12):
8180
files.append("run-python312.test")
8281

0 commit comments

Comments
 (0)