Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
more
  • Loading branch information
hauntsaninja committed Apr 16, 2026
commit eadf7923f5b6c0d90e166e0c01d0343a9b0b2057
8 changes: 4 additions & 4 deletions mypy/semanal_pass1.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ class SemanticAnalyzerPreAnalysis(TraverserVisitor):
import sys

def do_stuff() -> None:
if sys.version_info >= (3, 10):
import xyz # Only available in Python 3.10+
if sys.version_info >= (3, 11):
import xyz # Only available in Python 3.11+
xyz.whatever()
...

The block containing 'import xyz' is unreachable in Python 3 mode. The import
shouldn't be processed in Python 3 mode, even if the module happens to exist.
The block containing 'import xyz' is unreachable in Python 3.10 mode. The import
shouldn't be processed in Python 3.10 mode, even if the module happens to exist.
"""

def visit_file(self, file: MypyFile, fnam: str, mod_id: str, options: Options) -> None:
Expand Down
10 changes: 7 additions & 3 deletions test-data/unit/check-overloading.test
Original file line number Diff line number Diff line change
Expand Up @@ -5558,7 +5558,7 @@ class C: ...

@overload
def f1(g: A) -> A: ...
if sys.version_info >= (3, 9):
if sys.version_info >= (3, 10):
@overload
def f1(g: B) -> B: ...
def f1(g): ...
Expand All @@ -5569,12 +5569,16 @@ reveal_type(f1(B())) # N: Revealed type is "__main__.B"
def f2(g: A) -> A: ...
@overload
def f2(g: B) -> B: ...
if sys.version_info >= (3, 10):
if sys.version_info >= (3, 11):
@overload
def f2(g: C) -> C: ...
def f2(g): ...
reveal_type(f2(A())) # N: Revealed type is "__main__.A"
reveal_type(f2(C())) # N: Revealed type is "__main__.C"
reveal_type(f2(C())) # E: No overload variant of "f2" matches argument type "C" \
# N: Possible overload variants: \
# N: def f2(g: A) -> A \
# N: def f2(g: B) -> B \
# N: Revealed type is "Any"
[builtins fixtures/ops.pyi]

[case testOverloadIfMerging]
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-typeddict.test
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ reveal_type(p) # N: Revealed type is "TypedDict('__main__.EmptyDict', {})"
[typing fixtures/typing-typeddict.pyi]


[case testCanCreateTypedDictWithClassOldVersion]
[case testCanCreateTypedDictWithClassFunctionBases]
# Test that we can use class-syntax to merge function-based TypedDicts
from typing import TypedDict

Expand Down
33 changes: 0 additions & 33 deletions test-data/unit/deps.test
Original file line number Diff line number Diff line change
Expand Up @@ -1373,40 +1373,7 @@ def h() -> None:
<m.D.__new__> -> m.h
<m.D> -> m.D, m.h

[case testDataclassDepsOldVersion]
from dataclasses import dataclass

Z = int

@dataclass
class A:
x: Z

@dataclass
class B(A):
y: int
[builtins fixtures/dataclasses.pyi]

[out]
<m.A.(abstract)> -> <m.B.__init__>, m
<m.A.__dataclass_fields__> -> <m.B.__dataclass_fields__>
<m.A.__init__> -> <m.B.__init__>, m.B.__init__
<m.A.__match_args__> -> <m.B.__match_args__>
<m.A.__mypy-replace> -> <m.B.__mypy-replace>, m, m.B.__mypy-replace
<m.A.__new__> -> <m.B.__new__>
<m.A.x> -> <m.B.x>
<m.A.y> -> <m.B.y>
<m.A> -> m, m.A, m.B
<m.A[wildcard]> -> m
<m.B.__mypy-replace> -> m
<m.B.y> -> m
<m.B> -> m.B
<m.Z> -> m
<dataclasses.dataclass> -> m
<dataclasses> -> m

[case testDataclassDeps]
# flags: --python-version 3.10
from dataclasses import dataclass

Z = int
Expand Down
11 changes: 2 additions & 9 deletions test-data/unit/fixtures/notimplemented.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# builtins stub used in NotImplemented related cases.
from typing import Any

class object:
def __init__(self) -> None: pass
Expand All @@ -14,13 +13,7 @@ class tuple: pass
class ellipsis: pass
class list: pass

import sys

if sys.version_info >= (3, 10): # type: ignore
from types import NotImplementedType
NotImplemented: NotImplementedType
else:
class _NotImplementedType(Any): ...
NotImplemented: _NotImplementedType
from types import NotImplementedType
NotImplemented: NotImplementedType

class BaseException: pass
6 changes: 1 addition & 5 deletions test-data/unit/fixtures/type.pyi
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# builtins stub used in type-related test cases.

from typing import Any, Generic, TypeVar, List, Union
import sys
import types

T = TypeVar("T")
Expand Down Expand Up @@ -30,7 +29,4 @@ class str: pass
class ellipsis: pass
class float: pass

if sys.version_info >= (3, 10): # type: ignore
def isinstance(obj: object, class_or_tuple: type | types.UnionType, /) -> bool: ...
else:
def isinstance(obj: object, class_or_tuple: type, /) -> bool: ...
def isinstance(obj: object, class_or_tuple: type | types.UnionType, /) -> bool: ...
12 changes: 5 additions & 7 deletions test-data/unit/lib-stub/types.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from typing import Any, TypeVar
import sys

_T = TypeVar('_T')

Expand All @@ -13,11 +12,10 @@ class GenericAlias:
def __or__(self, o): ...
def __ror__(self, o): ...

if sys.version_info >= (3, 10):
class NoneType:
...
class NoneType:
...

class UnionType:
def __or__(self, x) -> UnionType: ...
class UnionType:
def __or__(self, x) -> UnionType: ...

class NotImplementedType: ...
class NotImplementedType: ...
62 changes: 0 additions & 62 deletions test-data/unit/merge.test
Original file line number Diff line number Diff line change
Expand Up @@ -646,68 +646,6 @@ TypeInfo<2>(
f<3>))

[case testNamedTuple_typeinfo]
# flags: --python-version 3.10
import target
[file target.py]
from typing import NamedTuple
class A: pass
N = NamedTuple('N', [('x', A)])
[file target.py.next]
from typing import NamedTuple
class A: pass
N = NamedTuple('N', [('x', A), ('y', A)])
[builtins fixtures/tuple.pyi]
[out]
TypeInfo<0>(
Name(target.A)
Bases(builtins.object<1>)
Mro(target.A<0>, builtins.object<1>)
Names())
TypeInfo<2>(
Name(target.N)
Bases(builtins.tuple[target.A<0>, ...]<3>)
Mro(target.N<2>, builtins.tuple<3>, typing.Sequence<4>, typing.Iterable<5>, builtins.object<1>)
Names(
_NT<6>
__annotations__<7> (builtins.dict[builtins.str<8>, Any]<9>)
__doc__<10> (builtins.str<8>)
__match_args__<11> (tuple[Literal['x']])
__new__<12>
_asdict<13>
_field_defaults<14> (builtins.dict[builtins.str<8>, Any]<9>)
_field_types<15> (builtins.dict[builtins.str<8>, Any]<9>)
_fields<16> (tuple[builtins.str<8>])
_make<17>
_replace<18>
_source<19> (builtins.str<8>)
x<20> (target.A<0>)))
==>
TypeInfo<0>(
Name(target.A)
Bases(builtins.object<1>)
Mro(target.A<0>, builtins.object<1>)
Names())
TypeInfo<2>(
Name(target.N)
Bases(builtins.tuple[target.A<0>, ...]<3>)
Mro(target.N<2>, builtins.tuple<3>, typing.Sequence<4>, typing.Iterable<5>, builtins.object<1>)
Names(
_NT<6>
__annotations__<7> (builtins.dict[builtins.str<8>, Any]<9>)
__doc__<10> (builtins.str<8>)
__match_args__<11> (tuple[Literal['x'], Literal['y']])
__new__<12>
_asdict<13>
_field_defaults<14> (builtins.dict[builtins.str<8>, Any]<9>)
_field_types<15> (builtins.dict[builtins.str<8>, Any]<9>)
_fields<16> (tuple[builtins.str<8>, builtins.str<8>])
_make<17>
_replace<18>
_source<19> (builtins.str<8>)
x<20> (target.A<0>)
y<21> (target.A<0>)))

[case testNamedTupleOldVersion_typeinfo]
import target
[file target.py]
from typing import NamedTuple
Expand Down
8 changes: 4 additions & 4 deletions test-data/unit/native-parser-imports.test
Original file line number Diff line number Diff line change
Expand Up @@ -636,13 +636,13 @@ else:
4: import reachable_exactly_310

[case testVersionInfoNotEquals]
# sys.version_info != (3, 9) should be always true for Python 3.10
# sys.version_info != (3, 11) should be always true for Python 3.10
import sys
if sys.version_info != (3, 9):
import reachable_not_39
if sys.version_info != (3, 11):
import reachable_not_311
[out]
2: import sys
4: import reachable_not_39
4: import reachable_not_311

[case testVersionInfoNotEqualsExact]
# sys.version_info != (3, 10) should be always false for Python 3.10
Expand Down
Loading