Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 707e4aa

Browse files
authored
Merge branch 'python:master' into untyped-def-end-line
2 parents c780ac1 + fb31409 commit 707e4aa

280 files changed

Lines changed: 8466 additions & 6419 deletions

File tree

Some content is hidden

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

.github/workflows/test.yml

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,53 +36,54 @@ jobs:
3636
arch: x64
3737
os: ubuntu-latest
3838
toxenv: py
39-
tox_extra_args: "-n 2"
39+
tox_extra_args: "-n 4"
4040
test_mypyc: true
4141
- name: Test suite with py38-windows-64
4242
python: '3.8'
4343
arch: x64
4444
os: windows-latest
4545
toxenv: py38
46-
tox_extra_args: "-n 2"
46+
tox_extra_args: "-n 4"
4747
- name: Test suite with py39-ubuntu
4848
python: '3.9'
4949
arch: x64
5050
os: ubuntu-latest
5151
toxenv: py
52-
tox_extra_args: "-n 2"
52+
tox_extra_args: "-n 4"
5353
- name: Test suite with py310-ubuntu
5454
python: '3.10'
5555
arch: x64
5656
os: ubuntu-latest
5757
toxenv: py
58-
tox_extra_args: "-n 2"
58+
tox_extra_args: "-n 4"
5959
- name: Test suite with py311-ubuntu, mypyc-compiled
6060
python: '3.11'
6161
arch: x64
6262
os: ubuntu-latest
6363
toxenv: py
64-
tox_extra_args: "-n 2"
64+
tox_extra_args: "-n 4"
6565
test_mypyc: true
6666
- name: Test suite with py312-ubuntu, mypyc-compiled
6767
python: '3.12'
6868
arch: x64
6969
os: ubuntu-latest
7070
toxenv: py
71-
tox_extra_args: "-n 2"
71+
tox_extra_args: "-n 4"
7272
test_mypyc: true
7373

7474
- name: mypyc runtime tests with py39-macos
7575
python: '3.9.18'
7676
arch: x64
77-
os: macos-latest
77+
# TODO: macos-13 is the last one to support Python 3.9, change it to macos-latest when updating the Python version
78+
os: macos-13
7879
toxenv: py
79-
tox_extra_args: "-n 2 mypyc/test/test_run.py mypyc/test/test_external.py"
80+
tox_extra_args: "-n 3 mypyc/test/test_run.py mypyc/test/test_external.py"
8081
- name: mypyc runtime tests with py38-debug-build-ubuntu
8182
python: '3.8.17'
8283
arch: x64
8384
os: ubuntu-latest
8485
toxenv: py
85-
tox_extra_args: "-n 2 mypyc/test/test_run.py mypyc/test/test_external.py"
86+
tox_extra_args: "-n 4 mypyc/test/test_run.py mypyc/test/test_external.py"
8687
debug_build: true
8788

8889
- name: Type check our own code (py38-ubuntu)
@@ -140,7 +141,9 @@ jobs:
140141
pip install -r test-requirements.txt
141142
CC=clang MYPYC_OPT_LEVEL=0 MYPY_USE_MYPYC=1 pip install -e .
142143
- name: Setup tox environment
143-
run: tox run -e ${{ matrix.toxenv }} --notest
144+
run: |
145+
tox run -e ${{ matrix.toxenv }} --notest
146+
python -c 'import os; print("os.cpu_count", os.cpu_count(), "os.sched_getaffinity", len(getattr(os, "sched_getaffinity", lambda *args: [])(0)))'
144147
- name: Test
145148
run: tox run -e ${{ matrix.toxenv }} --skip-pkg-install -- ${{ matrix.tox_extra_args }}
146149

@@ -189,4 +192,4 @@ jobs:
189192
- name: Setup tox environment
190193
run: tox run -e py --notest
191194
- name: Test
192-
run: tox run -e py --skip-pkg-install -- -n 2 mypyc/test/
195+
run: tox run -e py --skip-pkg-install -- -n 4 mypyc/test/

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
exclude: '^(mypyc/external/)|(mypy/typeshed/)' # Exclude all vendored code from lints
1+
exclude: '^(mypyc/external/)|(mypy/typeshed/)|misc/typeshed_patches' # Exclude all vendored code from lints
22
repos:
33
- repo: https://github.com/pre-commit/pre-commit-hooks
44
rev: v4.5.0 # must match test-requirements.txt

CHANGELOG.md

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,206 @@
11
# Mypy Release Notes
22

3+
## Next release
4+
5+
6+
7+
## Mypy 1.10
8+
9+
We’ve just uploaded mypy 1.10 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)). Mypy is a static type checker for Python. This release includes new features, performance improvements and bug fixes. You can install it as follows:
10+
11+
python3 -m pip install -U mypy
12+
13+
You can read the full documentation for this release on [Read the Docs](http://mypy.readthedocs.io).
14+
15+
#### Support TypeIs (PEP 742)
16+
17+
Mypy now supports `TypeIs` ([PEP 742](https://peps.python.org/pep-0742/)), which allows
18+
functions to narrow the type of a value, similar to `isinstance()`. Unlike `TypeGuard`,
19+
`TypeIs` can narrow in both the `if` and `else` branches of an if statement:
20+
21+
```python
22+
from typing_extensions import TypeIs
23+
24+
def is_str(s: object) -> TypeIs[str]:
25+
return isinstance(s, str)
26+
27+
def f(o: str | int) -> None:
28+
if is_str(o):
29+
# Type of o is 'str'
30+
...
31+
else:
32+
# Type of o is 'int'
33+
...
34+
```
35+
36+
`TypeIs` will be added to the `typing` module in Python 3.13, but it
37+
can be used on earlier Python versions by importing it from
38+
`typing_extensions`.
39+
40+
This feature was contributed by Jelle Zijlstra (PR [16898](https://github.com/python/mypy/pull/16898)).
41+
42+
#### Support TypeVar Defaults (PEP 696)
43+
44+
[PEP 696](https://peps.python.org/pep-0696/) adds support for type parameter defaults.
45+
Example:
46+
47+
```python
48+
from typing import Generic
49+
from typing_extensions import TypeVar
50+
51+
T = TypeVar("T", default=int)
52+
53+
class C(Generic[T]):
54+
...
55+
56+
x: C = ...
57+
y: C[str] = ...
58+
reveal_type(x) # C[int], because of the default
59+
reveal_type(y) # C[str]
60+
```
61+
62+
TypeVar defaults will be added to the `typing` module in Python 3.13, but they
63+
can be used with earlier Python releases by importing `TypeVar` from
64+
`typing_extensions`.
65+
66+
This feature was contributed by Marc Mueller (PR [16878](https://github.com/python/mypy/pull/16878)
67+
and PR [16925](https://github.com/python/mypy/pull/16925)).
68+
69+
#### Support TypeAliasType (PEP 695)
70+
As part of the initial steps towards implementing [PEP 695](https://peps.python.org/pep-0695/), mypy now supports `TypeAliasType`.
71+
`TypeAliasType` provides a backport of the new `type` statement in Python 3.12.
72+
73+
```python
74+
type ListOrSet[T] = list[T] | set[T]
75+
```
76+
77+
is equivalent to:
78+
79+
```python
80+
T = TypeVar("T")
81+
ListOrSet = TypeAliasType("ListOrSet", list[T] | set[T], type_params=(T,))
82+
```
83+
84+
Example of use in mypy:
85+
86+
```python
87+
from typing_extensions import TypeAliasType, TypeVar
88+
89+
NewUnionType = TypeAliasType("NewUnionType", int | str)
90+
x: NewUnionType = 42
91+
y: NewUnionType = 'a'
92+
z: NewUnionType = object() # error: Incompatible types in assignment (expression has type "object", variable has type "int | str") [assignment]
93+
94+
T = TypeVar("T")
95+
ListOrSet = TypeAliasType("ListOrSet", list[T] | set[T], type_params=(T,))
96+
a: ListOrSet[int] = [1, 2]
97+
b: ListOrSet[str] = {'a', 'b'}
98+
c: ListOrSet[str] = 'test' # error: Incompatible types in assignment (expression has type "str", variable has type "list[str] | set[str]") [assignment]
99+
```
100+
101+
`TypeAliasType` was added to the `typing` module in Python 3.12, but it can be used with earlier Python releases by importing from `typing_extensions`.
102+
103+
This feature was contributed by Ali Hamdan (PR [16926](https://github.com/python/mypy/pull/16926), PR [17038](https://github.com/python/mypy/pull/17038) and PR [17053](https://github.com/python/mypy/pull/17053))
104+
105+
#### Detect Additional Unsafe Uses of super()
106+
107+
Mypy will reject unsafe uses of `super()` more consistently, when the target has a
108+
trivial (empty) body. Example:
109+
110+
```python
111+
class Proto(Protocol):
112+
def method(self) -> int: ...
113+
114+
class Sub(Proto):
115+
def method(self) -> int:
116+
return super().meth() # Error (unsafe)
117+
```
118+
119+
This feature was contributed by Shantanu (PR [16756](https://github.com/python/mypy/pull/16756)).
120+
121+
#### Stubgen Improvements
122+
- Preserve empty tuple annotation (Ali Hamdan, PR [16907](https://github.com/python/mypy/pull/16907))
123+
- Add support for PEP 570 positional-only parameters (Ali Hamdan, PR [16904](https://github.com/python/mypy/pull/16904))
124+
- Replace obsolete typing aliases with builtin containers (Ali Hamdan, PR [16780](https://github.com/python/mypy/pull/16780))
125+
- Fix generated dataclass `__init__` signature (Ali Hamdan, PR [16906](https://github.com/python/mypy/pull/16906))
126+
127+
#### Mypyc Improvements
128+
129+
- Provide an easier way to define IR-to-IR transforms (Jukka Lehtosalo, PR [16998](https://github.com/python/mypy/pull/16998))
130+
- Implement lowering pass and add primitives for int (in)equality (Jukka Lehtosalo, PR [17027](https://github.com/python/mypy/pull/17027))
131+
- Implement lowering for remaining tagged integer comparisons (Jukka Lehtosalo, PR [17040](https://github.com/python/mypy/pull/17040))
132+
- Optimize away some bool/bit registers (Jukka Lehtosalo, PR [17022](https://github.com/python/mypy/pull/17022))
133+
- Remangle redefined names produced by async with (Richard Si, PR [16408](https://github.com/python/mypy/pull/16408))
134+
- Optimize TYPE_CHECKING to False at Runtime (Srinivas Lade, PR [16263](https://github.com/python/mypy/pull/16263))
135+
- Fix compilation of unreachable comprehensions (Richard Si, PR [15721](https://github.com/python/mypy/pull/15721))
136+
- Don't crash on non-inlinable final local reads (Richard Si, PR [15719](https://github.com/python/mypy/pull/15719))
137+
138+
#### Documentation Improvements
139+
- Import `TypedDict` from `typing` instead of `typing_extensions` (Riccardo Di Maio, PR [16958](https://github.com/python/mypy/pull/16958))
140+
- Add missing `mutable-override` to section title (James Braza, PR [16886](https://github.com/python/mypy/pull/16886))
141+
142+
#### Error Reporting Improvements
143+
144+
- Use lower-case generics more consistently in error messages (Jukka Lehtosalo, PR [17035](https://github.com/python/mypy/pull/17035))
145+
146+
#### Other Notable Changes and Fixes
147+
- Fix incorrect inferred type when accessing descriptor on union type (Matthieu Devlin, PR [16604](https://github.com/python/mypy/pull/16604))
148+
- Fix crash when expanding invalid `Unpack` in a `Callable` alias (Ali Hamdan, PR [17028](https://github.com/python/mypy/pull/17028))
149+
- Fix false positive when string formatting with string enum (roberfi, PR [16555](https://github.com/python/mypy/pull/16555))
150+
- Narrow individual items when matching a tuple to a sequence pattern (Loïc Simon, PR [16905](https://github.com/python/mypy/pull/16905))
151+
- Fix false positive from type variable within TypeGuard or TypeIs (Evgeniy Slobodkin, PR [17071](https://github.com/python/mypy/pull/17071))
152+
- Improve `yield from` inference for unions of generators (Shantanu, PR [16717](https://github.com/python/mypy/pull/16717))
153+
- Fix emulating hash method logic in `attrs` classes (Hashem, PR [17016](https://github.com/python/mypy/pull/17016))
154+
- Add reverted typeshed commit that uses `ParamSpec` for `functools.wraps` (Tamir Duberstein, PR [16942](https://github.com/python/mypy/pull/16942))
155+
- Fix type narrowing for `types.EllipsisType` (Shantanu, PR [17003](https://github.com/python/mypy/pull/17003))
156+
- Fix single item enum match type exhaustion (Oskari Lehto, PR [16966](https://github.com/python/mypy/pull/16966))
157+
- Improve type inference with empty collections (Marc Mueller, PR [16994](https://github.com/python/mypy/pull/16994))
158+
- Fix override checking for decorated property (Shantanu, PR [16856](https://github.com/python/mypy/pull/16856))
159+
- Fix narrowing on match with function subject (Edward Paget, PR [16503](https://github.com/python/mypy/pull/16503))
160+
- Allow `+N` within `Literal[...]` (Spencer Brown, PR [16910](https://github.com/python/mypy/pull/16910))
161+
- Experimental: Support TypedDict within `type[...]` (Marc Mueller, PR [16963](https://github.com/python/mypy/pull/16963))
162+
- Experimtental: Fix issue with TypedDict with optional keys in `type[...]` (Marc Mueller, PR [17068](https://github.com/python/mypy/pull/17068))
163+
164+
#### Typeshed Updates
165+
166+
Please see [git log](https://github.com/python/typeshed/commits/main?after=7c8e82fe483a40ec4cb0a2505cfdb0f3e7cc81d9+0&branch=main&path=stdlib) for full list of standard library typeshed stub changes.
167+
168+
169+
#### Acknowledgements
170+
Thanks to all mypy contributors who contributed to this release:
171+
172+
- Alex Waygood
173+
- Ali Hamdan
174+
- Edward Paget
175+
- Evgeniy Slobodkin
176+
- Hashem
177+
- hesam
178+
- Hugo van Kemenade
179+
- Ihor
180+
- James Braza
181+
- Jelle Zijlstra
182+
- jhance
183+
- Jukka Lehtosalo
184+
- Loïc Simon
185+
- Marc Mueller
186+
- Matthieu Devlin
187+
- Michael R. Crusoe
188+
- Nikita Sobolev
189+
- Oskari Lehto
190+
- Riccardo Di Maio
191+
- Richard Si
192+
- roberfi
193+
- Roman Solomatin
194+
- Sam Xifaras
195+
- Shantanu
196+
- Spencer Brown
197+
- Srinivas Lade
198+
- Tamir Duberstein
199+
- youkaichao
200+
201+
I’d also like to thank my employer, Dropbox, for supporting mypy development.
202+
203+
3204
## Mypy 1.9
4205

5206
We’ve just uploaded mypy 1.9 to the Python Package Index ([PyPI](https://pypi.org/project/mypy/)). Mypy is a static type checker for Python. This release includes new features, performance improvements and bug fixes. You can install it as follows:

CONTRIBUTING.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,23 @@ cd mypy
3030
#### (3) Create then activate a virtual environment
3131

3232
```bash
33-
# On Windows, the commands may be slightly different. For more details, see
34-
# https://docs.python.org/3/library/venv.html#creating-virtual-environments
3533
python3 -m venv venv
3634
source venv/bin/activate
3735
```
3836

37+
```bash
38+
# For Windows use
39+
python -m venv venv
40+
. venv/Scripts/activate
41+
42+
# For more details, see https://docs.python.org/3/library/venv.html#creating-virtual-environments
43+
```
44+
3945
#### (4) Install the test requirements and the project
4046

4147
```bash
42-
python3 -m pip install -r test-requirements.txt
43-
python3 -m pip install -e .
48+
python -m pip install -r test-requirements.txt
49+
python -m pip install -e .
4450
hash -r # This resets shell PATH cache, not necessary on Windows
4551
```
4652

0 commit comments

Comments
 (0)