Skip to content

Commit 90cc500

Browse files
committed
Merge remote-tracking branch 'upstream/master' into simple-parallel
2 parents 1c23255 + ece4d41 commit 90cc500

File tree

93 files changed

+1499
-542
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1499
-542
lines changed

.github/workflows/test.yml

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,22 @@ jobs:
3131
include:
3232
# Make sure to run mypyc compiled unit tests for both
3333
# the oldest and newest supported Python versions
34-
- name: Test suite with py39-ubuntu, mypyc-compiled
35-
python: '3.9'
36-
os: ubuntu-24.04-arm
37-
toxenv: py
38-
tox_extra_args: "-n 4"
39-
test_mypyc: true
40-
- name: Test suite with py310-ubuntu
34+
- name: Test suite with py310-ubuntu, mypyc-compiled
4135
python: '3.10'
4236
os: ubuntu-24.04-arm
4337
toxenv: py
4438
tox_extra_args: "-n 4"
39+
test_mypyc: true
4540
- name: Test suite with py311-ubuntu
4641
python: '3.11'
4742
os: ubuntu-24.04-arm
4843
toxenv: py
4944
tox_extra_args: "-n 4"
50-
- name: Test suite with py312-ubuntu, mypyc-compiled
45+
- name: Test suite with py312-ubuntu
5146
python: '3.12'
5247
os: ubuntu-24.04-arm
5348
toxenv: py
5449
tox_extra_args: "-n 4"
55-
test_mypyc: true
5650
- name: Test suite with py313-ubuntu, mypyc-compiled
5751
python: '3.13'
5852
os: ubuntu-24.04-arm
@@ -113,12 +107,12 @@ jobs:
113107
tox_extra_args: "-n 4 --mypy-num-workers=4 mypy/test/testcheck.py"
114108
test_mypyc: true
115109

116-
- name: Type check our own code (py39-ubuntu)
117-
python: '3.9'
110+
- name: Type check our own code (py310-ubuntu)
111+
python: '3.10'
118112
os: ubuntu-latest
119113
toxenv: type
120-
- name: Type check our own code (py39-windows-64)
121-
python: '3.9'
114+
- name: Type check our own code (py310-windows-64)
115+
python: '3.10'
122116
os: windows-latest
123117
toxenv: type
124118

.github/workflows/test_stubgenc.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ jobs:
3232
with:
3333
persist-credentials: false
3434

35-
- name: Setup 🐍 3.9
35+
- name: Setup 🐍 3.10
3636
uses: actions/setup-python@v5
3737
with:
38-
python-version: 3.9
38+
python-version: '3.10'
3939

4040
- name: Test stubgenc
4141
run: misc/test-stubgenc.sh

CHANGELOG.md

Lines changed: 134 additions & 35 deletions
Large diffs are not rendered by default.

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ hash -r # This resets shell PATH cache, not necessary on Windows
5151
```
5252

5353
> **Note**
54-
> You'll need Python 3.9 or higher to install all requirements listed in
54+
> You'll need Python 3.10 or higher to install all requirements listed in
5555
> test-requirements.txt
5656
5757
### Running tests

docs/source/error_code_list.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,28 @@ You can use :py:class:`~collections.abc.Callable` as the type for callable objec
215215
for x in objs:
216216
f(x)
217217
218+
.. _code-nonetype-type:
219+
220+
Check that NoneType is not used as a type (annotation) [nonetype-type]
221+
----------------------------------------------------------------------
222+
223+
The preferred way to annotate the type of `None` is `None`.
224+
`NoneType` is equivalent, but mypy won't allow it by default.
225+
226+
.. code-block:: python
227+
228+
from types import NoneType
229+
def f(x: None) -> None:
230+
reveal_type(x) # note: Revealed type is "None"
231+
232+
# error: NoneType should not be used as a type, please use None instead [nonetype-type]
233+
def g(x: NoneType) -> None:
234+
reveal_type(x) # note: Revealed type is "None"
235+
236+
# error: NoneType should not be used as a type, please use None instead [nonetype-type]
237+
x1: NoneType = None
238+
x2: None = None # OK
239+
218240
.. _code-metaclass:
219241

220242
Check the validity of a class's metaclass [metaclass]

docs/source/getting_started.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ may not make much sense otherwise.
1616
Installing and running mypy
1717
***************************
1818

19-
Mypy requires Python 3.9 or later to run. You can install mypy using pip:
19+
Mypy requires Python 3.10 or later to run. You can install mypy using pip:
2020

2121
.. code-block:: shell
2222

mypy/argmap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ def map_actuals_to_formals(
3636
The result contains a list of caller argument indexes mapping to each
3737
callee argument index, indexed by callee index.
3838
39-
The caller_arg_type argument should evaluate to the type of the actual
40-
argument type with the given index.
39+
The actual_arg_type argument should evaluate to the type of the actual
40+
argument with the given index.
4141
"""
4242
nformals = len(formal_kinds)
4343
formal_to_actual: list[list[int]] = [[] for i in range(nformals)]

mypy/binder.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from collections import defaultdict
44
from collections.abc import Iterator
55
from contextlib import contextmanager
6-
from typing import NamedTuple, Optional, Union
6+
from typing import NamedTuple
77
from typing_extensions import TypeAlias as _TypeAlias
88

99
from mypy.erasetype import remove_instance_last_known_values
@@ -39,7 +39,7 @@
3939
)
4040
from mypy.typevars import fill_typevars_with_any
4141

42-
BindableExpression: _TypeAlias = Union[IndexExpr, MemberExpr, NameExpr]
42+
BindableExpression: _TypeAlias = IndexExpr | MemberExpr | NameExpr
4343

4444

4545
class CurrentType(NamedTuple):
@@ -81,7 +81,7 @@ def __repr__(self) -> str:
8181
return f"Frame({self.id}, {self.types}, {self.unreachable}, {self.conditional_frame})"
8282

8383

84-
Assigns = defaultdict[Expression, list[tuple[Type, Optional[Type]]]]
84+
Assigns = defaultdict[Expression, list[tuple[Type, Type | None]]]
8585

8686

8787
class ConditionalTypeBinder:

mypy/cache.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
from __future__ import annotations
4949

5050
from collections.abc import Sequence
51-
from typing import Any, Final, Union
51+
from typing import Any, Final
5252
from typing_extensions import TypeAlias as _TypeAlias
5353

5454
from librt.internal import (
@@ -391,10 +391,8 @@ def write_str_opt_list(data: WriteBuffer, value: list[str | None]) -> None:
391391
write_str_opt(data, item)
392392

393393

394-
JsonValue: _TypeAlias = Union[None, int, str, bool, list["JsonValue"], dict[str, "JsonValue"]]
395-
JsonValueEx: _TypeAlias = Union[
396-
None, int, str, bool, list["JsonValueEx"], dict[str, "JsonValueEx"], tuple["JsonValueEx", ...]
397-
]
394+
JsonValue: _TypeAlias = None | int | str | bool | list["JsonValue"] | dict[str, "JsonValue"]
395+
JsonValueEx: _TypeAlias = None | int | str | bool | list["JsonValueEx"] | dict[str, "JsonValueEx"] | tuple["JsonValueEx", ...]
398396

399397

400398
def read_json_value(data: ReadBuffer) -> JsonValue:

mypy/checker.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,7 @@
66
from collections import defaultdict
77
from collections.abc import Iterable, Iterator, Mapping, Sequence, Set as AbstractSet
88
from contextlib import ExitStack, contextmanager
9-
from typing import (
10-
Callable,
11-
Final,
12-
Generic,
13-
Literal,
14-
NamedTuple,
15-
Optional,
16-
TypeVar,
17-
Union,
18-
cast,
19-
overload,
20-
)
9+
from typing import Callable, Final, Generic, Literal, NamedTuple, TypeVar, cast, overload
2110
from typing_extensions import TypeAlias as _TypeAlias, TypeGuard
2211

2312
import mypy.checkexpr
@@ -249,8 +238,8 @@
249238
# Maximum length of fixed tuple types inferred when narrowing from variadic tuples.
250239
MAX_PRECISE_TUPLE_SIZE: Final = 8
251240

252-
DeferredNodeType: _TypeAlias = Union[FuncDef, OverloadedFuncDef, Decorator]
253-
FineGrainedDeferredNodeType: _TypeAlias = Union[FuncDef, MypyFile, OverloadedFuncDef]
241+
DeferredNodeType: _TypeAlias = FuncDef | OverloadedFuncDef | Decorator
242+
FineGrainedDeferredNodeType: _TypeAlias = FuncDef | MypyFile | OverloadedFuncDef
254243

255244

256245
# A node which is postponed to be processed during the next pass.
@@ -283,7 +272,7 @@ class FineGrainedDeferredNode(NamedTuple):
283272
# (such as two references to the same variable). TODO: it would
284273
# probably be better to have the dict keyed by the nodes' literal_hash
285274
# field instead.
286-
TypeMap: _TypeAlias = Optional[dict[Expression, Type]]
275+
TypeMap: _TypeAlias = dict[Expression, Type] | None
287276

288277

289278
# Keeps track of partial types in a single scope. In fine-grained incremental
@@ -5309,16 +5298,22 @@ def get_types_from_except_handler(self, typ: Type, n: Expression) -> list[Type]:
53095298
"""Helper for check_except_handler_test to retrieve handler types."""
53105299
typ = get_proper_type(typ)
53115300
if isinstance(typ, TupleType):
5312-
return typ.items
5301+
merged_type = make_simplified_union(typ.items)
5302+
if isinstance(merged_type, UnionType):
5303+
return merged_type.relevant_items()
5304+
return [merged_type]
5305+
elif is_named_instance(typ, "builtins.tuple"):
5306+
# variadic tuple
5307+
merged_type = make_simplified_union((typ.args[0],))
5308+
if isinstance(merged_type, UnionType):
5309+
return merged_type.relevant_items()
5310+
return [merged_type]
53135311
elif isinstance(typ, UnionType):
53145312
return [
53155313
union_typ
53165314
for item in typ.relevant_items()
53175315
for union_typ in self.get_types_from_except_handler(item, n)
53185316
]
5319-
elif is_named_instance(typ, "builtins.tuple"):
5320-
# variadic tuple
5321-
return [typ.args[0]]
53225317
else:
53235318
return [typ]
53245319

0 commit comments

Comments
 (0)