Skip to content

Commit ec04f73

Browse files
authored
Update sys.version_info guards after dropping Python 3.8 (#18338)
1 parent 645081f commit ec04f73

File tree

7 files changed

+14
-59
lines changed

7 files changed

+14
-59
lines changed

mypy/fastparse.py

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import copy
43
import re
54
import sys
65
import warnings
@@ -241,13 +240,6 @@ def parse(
241240
path=fnam,
242241
).visit(ast)
243242
except SyntaxError as e:
244-
# alias to please mypyc
245-
is_py38_or_earlier = sys.version_info < (3, 9)
246-
if is_py38_or_earlier and e.filename == "<fstring>":
247-
# In Python 3.8 and earlier, syntax errors in f-strings have lineno relative to the
248-
# start of the f-string. This would be misleading, as mypy will report the error as the
249-
# lineno within the file.
250-
e.lineno = None
251243
message = e.msg
252244
if feature_version > sys.version_info.minor and message.startswith("invalid syntax"):
253245
python_version_str = f"{options.python_version[0]}.{options.python_version[1]}"
@@ -2069,40 +2061,15 @@ def visit_Index(self, n: ast3.Index) -> Type:
20692061
def visit_Slice(self, n: ast3.Slice) -> Type:
20702062
return self.invalid_type(n, note="did you mean to use ',' instead of ':' ?")
20712063

2072-
# Subscript(expr value, slice slice, expr_context ctx) # Python 3.8 and before
20732064
# Subscript(expr value, expr slice, expr_context ctx) # Python 3.9 and later
20742065
def visit_Subscript(self, n: ast3.Subscript) -> Type:
2075-
if sys.version_info >= (3, 9): # Really 3.9a5 or later
2076-
sliceval: Any = n.slice
2077-
# Python 3.8 or earlier use a different AST structure for subscripts
2078-
elif isinstance(n.slice, ast3.Index):
2079-
sliceval: Any = n.slice.value
2080-
elif isinstance(n.slice, ast3.Slice):
2081-
sliceval = copy.deepcopy(n.slice) # so we don't mutate passed AST
2082-
if getattr(sliceval, "col_offset", None) is None:
2083-
# Fix column information so that we get Python 3.9+ message order
2084-
sliceval.col_offset = sliceval.lower.col_offset
2085-
else:
2086-
assert isinstance(n.slice, ast3.ExtSlice)
2087-
dims = cast(List[ast3.expr], copy.deepcopy(n.slice.dims))
2088-
for s in dims:
2089-
# These fields don't actually have a col_offset attribute but we add
2090-
# it manually.
2091-
if getattr(s, "col_offset", None) is None:
2092-
if isinstance(s, ast3.Index):
2093-
s.col_offset = s.value.col_offset
2094-
elif isinstance(s, ast3.Slice):
2095-
assert s.lower is not None
2096-
s.col_offset = s.lower.col_offset
2097-
sliceval = ast3.Tuple(dims, n.ctx)
2098-
20992066
empty_tuple_index = False
2100-
if isinstance(sliceval, ast3.Tuple):
2101-
params = self.translate_expr_list(sliceval.elts)
2102-
if len(sliceval.elts) == 0:
2067+
if isinstance(n.slice, ast3.Tuple):
2068+
params = self.translate_expr_list(n.slice.elts)
2069+
if len(n.slice.elts) == 0:
21032070
empty_tuple_index = True
21042071
else:
2105-
params = [self.visit(sliceval)]
2072+
params = [self.visit(n.slice)]
21062073

21072074
value = self.visit(n.value)
21082075
if isinstance(value, UnboundType) and not value.args:

mypy/pyinfo.py

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

33
"""Utilities to find the site and prefix information of a Python executable.
44
5-
This file MUST remain compatible with all Python 3.8+ versions. Since we cannot make any
5+
This file MUST remain compatible with all Python 3.9+ versions. Since we cannot make any
66
assumptions about the Python being executed, this module should not use *any* dependencies outside
7-
of the standard library found in Python 3.8. This file is run each mypy run, so it should be kept
7+
of the standard library found in Python 3.9. This file is run each mypy run, so it should be kept
88
as fast as possible.
99
"""
1010
import sys

mypy/test/testcheck.py

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

3939
# Tests that use Python version specific features:
40-
if sys.version_info < (3, 9):
41-
typecheck_files.remove("check-python39.test")
4240
if sys.version_info < (3, 10):
4341
typecheck_files.remove("check-python310.test")
4442
if sys.version_info < (3, 11):

mypy/test/testpep561.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ def upgrade_pip(python_executable: str) -> None:
5252
sys.version_info >= (3, 11)
5353
or (3, 10, 3) <= sys.version_info < (3, 11)
5454
or (3, 9, 11) <= sys.version_info < (3, 10)
55-
or (3, 8, 13) <= sys.version_info < (3, 9)
5655
):
5756
# Skip for more recent Python releases which come with pip>=21.3.1
5857
# out of the box - for performance reasons.

mypy/test/teststubtest.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,12 +1533,11 @@ def test_dunders(self) -> Iterator[Case]:
15331533
runtime="class C:\n def __init_subclass__(cls, e=1, **kwargs): pass",
15341534
error=None,
15351535
)
1536-
if sys.version_info >= (3, 9):
1537-
yield Case(
1538-
stub="class D:\n def __class_getitem__(cls, type: type) -> type: ...",
1539-
runtime="class D:\n def __class_getitem__(cls, type): ...",
1540-
error=None,
1541-
)
1536+
yield Case(
1537+
stub="class D:\n def __class_getitem__(cls, type: type) -> type: ...",
1538+
runtime="class D:\n def __class_getitem__(cls, type): ...",
1539+
error=None,
1540+
)
15421541

15431542
@collect_cases
15441543
def test_not_subclassable(self) -> Iterator[Case]:

mypy/util.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,7 @@
3030

3131
T = TypeVar("T")
3232

33-
if sys.version_info >= (3, 9):
34-
TYPESHED_DIR: Final = str(importlib_resources.files("mypy") / "typeshed")
35-
else:
36-
with importlib_resources.path(
37-
"mypy", # mypy-c doesn't support __package__
38-
"py.typed", # a marker file for type information, we assume typeshed to live in the same dir
39-
) as _resource:
40-
TYPESHED_DIR = str(_resource.parent / "typeshed")
41-
33+
TYPESHED_DIR: Final = str(importlib_resources.files("mypy") / "typeshed")
4234

4335
ENCODING_RE: Final = re.compile(rb"([ \t\v]*#.*(\r\n?|\n))??[ \t\v]*#.*coding[:=][ \t]*([-\w.]+)")
4436

@@ -490,7 +482,7 @@ def get_unique_redefinition_name(name: str, existing: Container[str]) -> str:
490482
def check_python_version(program: str) -> None:
491483
"""Report issues with the Python used to run mypy, dmypy, or stubgen"""
492484
# Check for known bad Python versions.
493-
if sys.version_info[:2] < (3, 9):
485+
if sys.version_info[:2] < (3, 9): # noqa: UP036, RUF100
494486
sys.exit(
495487
"Running {name} with Python 3.8 or lower is not supported; "
496488
"please upgrade to 3.9 or newer".format(name=program)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import sys
99
from typing import TYPE_CHECKING, Any
1010

11-
if sys.version_info < (3, 9, 0):
11+
if sys.version_info < (3, 9, 0): # noqa: UP036, RUF100
1212
sys.stderr.write("ERROR: You need Python 3.9 or later to use mypy.\n")
1313
exit(1)
1414

0 commit comments

Comments
 (0)