Skip to content

Commit 21d3090

Browse files
authored
Further cleanup after dropping Python 3.8 (#19197)
1 parent 5fbfff9 commit 21d3090

File tree

7 files changed

+14
-34
lines changed

7 files changed

+14
-34
lines changed

mypy/checkexpr.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4420,7 +4420,7 @@ def visit_index_with_type(
44204420
elif isinstance(left_type, FunctionLike) and left_type.is_type_obj():
44214421
if left_type.type_object().is_enum:
44224422
return self.visit_enum_index_expr(left_type.type_object(), e.index, e)
4423-
elif self.chk.options.python_version >= (3, 9) and (
4423+
elif (
44244424
left_type.type_object().type_vars
44254425
or left_type.type_object().fullname == "builtins.type"
44264426
):

mypy/semanal.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@
265265
TPDICT_NAMES,
266266
TYPE_ALIAS_NAMES,
267267
TYPE_CHECK_ONLY_NAMES,
268+
TYPE_NAMES,
268269
TYPE_VAR_LIKE_NAMES,
269270
TYPED_NAMEDTUPLE_NAMES,
270271
UNPACK_TYPE_NAMES,
@@ -1116,21 +1117,7 @@ def is_expected_self_type(self, typ: Type, is_classmethod: bool) -> bool:
11161117
return self.is_expected_self_type(typ.item, is_classmethod=False)
11171118
if isinstance(typ, UnboundType):
11181119
sym = self.lookup_qualified(typ.name, typ, suppress_errors=True)
1119-
if (
1120-
sym is not None
1121-
and (
1122-
sym.fullname == "typing.Type"
1123-
or (
1124-
sym.fullname == "builtins.type"
1125-
and (
1126-
self.is_stub_file
1127-
or self.is_future_flag_set("annotations")
1128-
or self.options.python_version >= (3, 9)
1129-
)
1130-
)
1131-
)
1132-
and typ.args
1133-
):
1120+
if sym is not None and sym.fullname in TYPE_NAMES and typ.args:
11341121
return self.is_expected_self_type(typ.args[0], is_classmethod=False)
11351122
return False
11361123
if isinstance(typ, TypeVarType):

mypy/typeanal.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@
6565
FINAL_TYPE_NAMES,
6666
LITERAL_TYPE_NAMES,
6767
NEVER_NAMES,
68+
TUPLE_NAMES,
6869
TYPE_ALIAS_NAMES,
70+
TYPE_NAMES,
6971
UNPACK_TYPE_NAMES,
7072
AnyType,
7173
BoolTypeQuery,
@@ -607,10 +609,7 @@ def try_analyze_special_unbound_type(self, t: UnboundType, fullname: str) -> Typ
607609
code=codes.VALID_TYPE,
608610
)
609611
return AnyType(TypeOfAny.from_error)
610-
elif fullname == "typing.Tuple" or (
611-
fullname == "builtins.tuple"
612-
and (self.always_allow_new_syntax or self.options.python_version >= (3, 9))
613-
):
612+
elif fullname in TUPLE_NAMES:
614613
# Tuple is special because it is involved in builtin import cycle
615614
# and may be not ready when used.
616615
sym = self.api.lookup_fully_qualified_or_none("builtins.tuple")
@@ -645,10 +644,7 @@ def try_analyze_special_unbound_type(self, t: UnboundType, fullname: str) -> Typ
645644
return make_optional_type(item)
646645
elif fullname == "typing.Callable":
647646
return self.analyze_callable_type(t)
648-
elif fullname == "typing.Type" or (
649-
fullname == "builtins.type"
650-
and (self.always_allow_new_syntax or self.options.python_version >= (3, 9))
651-
):
647+
elif fullname in TYPE_NAMES:
652648
if len(t.args) == 0:
653649
if fullname == "typing.Type":
654650
any_type = self.get_omitted_any(t)

mypy/types.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@
8484
TypeVisitor as TypeVisitor,
8585
)
8686

87+
TUPLE_NAMES: Final = ("builtins.tuple", "typing.Tuple")
88+
TYPE_NAMES: Final = ("builtins.type", "typing.Type")
89+
8790
TYPE_VAR_LIKE_NAMES: Final = (
8891
"typing.TypeVar",
8992
"typing_extensions.TypeVar",

mypyc/irbuild/classdef.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,11 +564,11 @@ def find_non_ext_metaclass(builder: IRBuilder, cdef: ClassDef, bases: Value) ->
564564
if cdef.metaclass:
565565
declared_metaclass = builder.accept(cdef.metaclass)
566566
else:
567-
if cdef.info.typeddict_type is not None and builder.options.capi_version >= (3, 9):
567+
if cdef.info.typeddict_type is not None:
568568
# In Python 3.9, the metaclass for class-based TypedDict is typing._TypedDictMeta.
569569
# We can't easily calculate it generically, so special case it.
570570
return builder.get_module_attr("typing", "_TypedDictMeta", cdef.line)
571-
elif cdef.info.is_named_tuple and builder.options.capi_version >= (3, 9):
571+
elif cdef.info.is_named_tuple:
572572
# In Python 3.9, the metaclass for class-based NamedTuple is typing.NamedTupleMeta.
573573
# We can't easily calculate it generically, so special case it.
574574
return builder.get_module_attr("typing", "NamedTupleMeta", cdef.line)

test-data/unit/check-selftype.test

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,7 +1707,6 @@ class C:
17071707
[builtins fixtures/classmethod.pyi]
17081708

17091709
[case testTypingSelfRedundantAllowed_pep585]
1710-
# flags: --python-version 3.9
17111710
from typing import Self
17121711

17131712
class C:
@@ -1742,7 +1741,6 @@ class C:
17421741
[builtins fixtures/classmethod.pyi]
17431742

17441743
[case testTypingSelfRedundantWarning_pep585]
1745-
# flags: --python-version 3.9
17461744
# mypy: enable-error-code="redundant-self"
17471745

17481746
from typing import Self

test-data/unit/check-union-or-syntax.test

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ x: List[int | str]
6767
reveal_type(x) # N: Revealed type is "builtins.list[Union[builtins.int, builtins.str]]"
6868
[builtins fixtures/list.pyi]
6969

70-
[case testUnionOrSyntaxWithQuotedFunctionTypesPre310]
71-
# flags: --python-version 3.9
70+
[case testUnionOrSyntaxWithQuotedFunctionTypes]
7271
from typing import Union
7372
def f(x: 'Union[int, str, None]') -> 'Union[int, None]':
7473
reveal_type(x) # N: Revealed type is "Union[builtins.int, builtins.str, None]"
@@ -80,8 +79,7 @@ def g(x: "int | str | None") -> "int | None":
8079
return 42
8180
reveal_type(g) # N: Revealed type is "def (x: Union[builtins.int, builtins.str, None]) -> Union[builtins.int, None]"
8281

83-
[case testUnionOrSyntaxWithQuotedVariableTypesPre310]
84-
# flags: --python-version 3.9
82+
[case testUnionOrSyntaxWithQuotedVariableTypes]
8583
y: "int | str" = 42
8684
reveal_type(y) # N: Revealed type is "Union[builtins.int, builtins.str]"
8785

@@ -137,7 +135,6 @@ x: int | None
137135
x: int | None # E: X | Y syntax for unions requires Python 3.10
138136

139137
[case testUnionOrSyntaxInStubFile]
140-
# flags: --python-version 3.9
141138
from lib import x
142139
[file lib.pyi]
143140
x: int | None
@@ -187,7 +184,6 @@ def g(x: int | str | tuple[int, str] | C) -> None:
187184
[builtins fixtures/isinstance_python3_10.pyi]
188185

189186
[case testUnionOrSyntaxInIsinstanceNotSupported]
190-
# flags: --python-version 3.9
191187
from typing import Union
192188
def f(x: Union[int, str, None]) -> None:
193189
if isinstance(x, int | str):

0 commit comments

Comments
 (0)