Skip to content

Commit fdd848f

Browse files
committed
Update sys.version_info guards after dropping Python 3.8
1 parent b3eff87 commit fdd848f

File tree

5 files changed

+12
-49
lines changed

5 files changed

+12
-49
lines changed

mypy/fastparse.py

Lines changed: 4 additions & 30 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
@@ -2069,40 +2068,15 @@ def visit_Index(self, n: ast3.Index) -> Type:
20692068
def visit_Slice(self, n: ast3.Slice) -> Type:
20702069
return self.invalid_type(n, note="did you mean to use ',' instead of ':' ?")
20712070

2072-
# Subscript(expr value, slice slice, expr_context ctx) # Python 3.8 and before
20732071
# Subscript(expr value, expr slice, expr_context ctx) # Python 3.9 and later
20742072
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-
20992073
empty_tuple_index = False
2100-
if isinstance(sliceval, ast3.Tuple):
2101-
params = self.translate_expr_list(sliceval.elts)
2102-
if len(sliceval.elts) == 0:
2074+
if isinstance(n.slice, ast3.Tuple):
2075+
params = self.translate_expr_list(n.slice.elts)
2076+
if len(n.slice.elts) == 0:
21032077
empty_tuple_index = True
21042078
else:
2105-
params = [self.visit(sliceval)]
2079+
params = [self.visit(n.slice)]
21062080

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

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/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)