Skip to content

Commit f470eac

Browse files
Merge branch 'master' into cli
2 parents 7f13ac0 + 5bdfe7e commit f470eac

File tree

220 files changed

+12068
-2866
lines changed

Some content is hidden

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

220 files changed

+12068
-2866
lines changed

.github/workflows/mypy_primer.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ jobs:
6767
--debug \
6868
--additional-flags="--debug-serialize" \
6969
--output concise \
70+
--mypy-install-librt \
7071
| tee diff_${{ matrix.shard-index }}.txt
7172
) || [ $? -eq 1 ]
7273
- if: ${{ matrix.shard-index == 0 }}

.github/workflows/test.yml

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,38 @@ jobs:
5959
toxenv: py
6060
tox_extra_args: "-n 4"
6161
test_mypyc: true
62-
- name: Test suite with py313-windows-64
63-
python: '3.13'
62+
- name: Test suite with py314-ubuntu, mypyc-compiled
63+
python: '3.14'
64+
os: ubuntu-24.04-arm
65+
toxenv: py
66+
tox_extra_args: "-n 4"
67+
test_mypyc: true
68+
- name: Test suite with py314-windows-64
69+
python: '3.14'
6470
os: windows-latest
6571
toxenv: py
6672
tox_extra_args: "-n 4"
6773

68-
- name: Test suite with py314-dev-ubuntu
69-
python: '3.14-dev'
70-
os: ubuntu-24.04-arm
74+
# - name: Test suite with py315-dev-ubuntu
75+
# python: '3.15-dev'
76+
# os: ubuntu-24.04-arm
77+
# toxenv: py
78+
# tox_extra_args: "-n 4"
79+
# # allow_failure: true
80+
# test_mypyc: true
81+
82+
- name: mypyc runtime tests with py313-macos
83+
python: '3.13'
84+
os: macos-latest
7185
toxenv: py
72-
tox_extra_args: "-n 4"
73-
# allow_failure: true
74-
test_mypyc: true
86+
tox_extra_args: "-n 3 mypyc/test/test_run.py mypyc/test/test_external.py"
7587

76-
- name: mypyc runtime tests with py39-macos
77-
python: '3.9.21'
78-
# TODO: macos-13 is the last one to support Python 3.9, change it to macos-latest when updating the Python version
79-
os: macos-13
88+
- name: mypyc runtime tests with py310-ubuntu
89+
python: '3.10'
90+
os: ubuntu-latest
8091
toxenv: py
8192
tox_extra_args: "-n 3 mypyc/test/test_run.py mypyc/test/test_external.py"
93+
8294
# This is broken. See
8395
# - https://github.com/python/mypy/issues/17819
8496
# - https://github.com/python/mypy/pull/17822

.github/workflows/test_stubgenc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
- 'mypy/stubgenc.py'
1212
- 'mypy/stubdoc.py'
1313
- 'mypy/stubutil.py'
14-
- 'test-data/stubgen/**'
14+
- 'test-data/pybind11_fixtures/**'
1515

1616
permissions:
1717
contents: read

.pre-commit-config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ repos:
66
- id: trailing-whitespace
77
- id: end-of-file-fixer
88
- repo: https://github.com/psf/black-pre-commit-mirror
9-
rev: 25.1.0
9+
rev: 25.9.0
1010
hooks:
1111
- id: black
1212
exclude: '^(test-data/)'
1313
- repo: https://github.com/astral-sh/ruff-pre-commit
14-
rev: v0.11.4
14+
rev: v0.14.3
1515
hooks:
16-
- id: ruff
16+
- id: ruff-check
1717
args: [--exit-non-zero-on-fix]
1818
- repo: https://github.com/python-jsonschema/check-jsonschema
1919
rev: 0.32.1
@@ -41,7 +41,7 @@ repos:
4141
# actionlint has a shellcheck integration which extracts shell scripts in `run:` steps from GitHub Actions
4242
# and checks these with shellcheck. This is arguably its most useful feature,
4343
# but the integration only works if shellcheck is installed
44-
- "github.com/wasilibs/go-shellcheck/cmd/shellcheck@v0.10.0"
44+
- "github.com/wasilibs/go-shellcheck/cmd/shellcheck@v0.11.1"
4545
- repo: https://github.com/woodruffw/zizmor-pre-commit
4646
rev: v1.5.2
4747
hooks:

docs/source/command_line.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ definitions or calls.
372372

373373
.. option:: --untyped-calls-exclude
374374

375-
This flag allows to selectively disable :option:`--disallow-untyped-calls`
375+
This flag allows one to selectively disable :option:`--disallow-untyped-calls`
376376
for functions and methods defined in specific packages, modules, or classes.
377377
Note that each exclude entry acts as a prefix. For example (assuming there
378378
are no type annotations for ``third_party_lib`` available):
@@ -562,7 +562,7 @@ potentially problematic or redundant in some way.
562562

563563
.. option:: --deprecated-calls-exclude
564564

565-
This flag allows to selectively disable :ref:`deprecated<code-deprecated>` warnings
565+
This flag allows one to selectively disable :ref:`deprecated<code-deprecated>` warnings
566566
for functions and methods defined in specific packages, modules, or classes.
567567
Note that each exclude entry acts as a prefix. For example (assuming ``foo.A.func`` is deprecated):
568568

@@ -1161,7 +1161,7 @@ format into the specified directory.
11611161
Experimental features
11621162
*****************************************
11631163

1164-
.. option:: --enable-incomplete-feature {PreciseTupleTypes, InlineTypedDict}
1164+
.. option:: --enable-incomplete-feature {PreciseTupleTypes,InlineTypedDict}
11651165

11661166
Some features may require several mypy releases to implement, for example
11671167
due to their complexity, potential for backwards incompatibility, or
@@ -1213,8 +1213,8 @@ List of currently incomplete/experimental features:
12131213

12141214
.. code-block:: python
12151215
1216-
def test_values() -> {"int": int, "str": str}:
1217-
return {"int": 42, "str": "test"}
1216+
def test_values() -> {"width": int, "description": str}:
1217+
return {"width": 42, "description": "test"}
12181218
12191219
.. option:: --find-occurrences CLASS.MEMBER
12201220

docs/source/common_issues.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ This example demonstrates both safe and unsafe overrides:
731731
732732
class NarrowerReturn(A):
733733
# A more specific return type is fine
734-
def test(self, t: Sequence[int]) -> List[str]: # OK
734+
def test(self, t: Sequence[int]) -> list[str]: # OK
735735
...
736736
737737
class GeneralizedReturn(A):
@@ -746,7 +746,7 @@ not necessary:
746746
.. code-block:: python
747747
748748
class NarrowerArgument(A):
749-
def test(self, t: List[int]) -> Sequence[str]: # type: ignore[override]
749+
def test(self, t: list[int]) -> Sequence[str]: # type: ignore[override]
750750
...
751751
752752
.. _unreachable:

docs/source/error_code_list.rst

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,8 +1032,8 @@ Warn about top level await expressions [top-level-await]
10321032
This error code is separate from the general ``[syntax]`` errors, because in
10331033
some environments (e.g. IPython) a top level ``await`` is allowed. In such
10341034
environments a user may want to use ``--disable-error-code=top-level-await``,
1035-
that allows to still have errors for other improper uses of ``await``, for
1036-
example:
1035+
which allows one to still have errors for other improper uses of ``await``,
1036+
for example:
10371037

10381038
.. code-block:: python
10391039
@@ -1286,6 +1286,65 @@ type must be a subtype of the original type::
12861286
def g(x: object) -> TypeIs[str]: # OK
12871287
...
12881288

1289+
.. _code-maybe-unrecognized-str-typeform:
1290+
1291+
String appears in a context which expects a TypeForm [maybe-unrecognized-str-typeform]
1292+
--------------------------------------------------------------------------------------
1293+
1294+
TypeForm literals may contain string annotations:
1295+
1296+
.. code-block:: python
1297+
1298+
typx1: TypeForm = str | None
1299+
typx2: TypeForm = 'str | None' # OK
1300+
typx3: TypeForm = 'str' | None # OK
1301+
1302+
However TypeForm literals containing a string annotation can only be recognized
1303+
by mypy in the following locations:
1304+
1305+
.. code-block:: python
1306+
1307+
typx_var: TypeForm = 'str | None' # assignment r-value
1308+
1309+
def func(typx_param: TypeForm) -> TypeForm:
1310+
return 'str | None' # returned expression
1311+
1312+
func('str | None') # callable's argument
1313+
1314+
If you try to use a string annotation in some other location
1315+
which expects a TypeForm, the string value will always be treated as a ``str``
1316+
even if a ``TypeForm`` would be more appropriate and this error code
1317+
will be generated:
1318+
1319+
.. code-block:: python
1320+
1321+
# Error: TypeForm containing a string annotation cannot be recognized here. Surround with TypeForm(...) to recognize. [maybe-unrecognized-str-typeform]
1322+
# Error: List item 0 has incompatible type "str"; expected "TypeForm[Any]" [list-item]
1323+
list_of_typx: list[TypeForm] = ['str | None', float]
1324+
1325+
Fix the error by surrounding the entire type with ``TypeForm(...)``:
1326+
1327+
.. code-block:: python
1328+
1329+
list_of_typx: list[TypeForm] = [TypeForm('str | None'), float] # OK
1330+
1331+
Similarly, if you try to use a string literal in a location which expects a
1332+
TypeForm, this error code will be generated:
1333+
1334+
.. code-block:: python
1335+
1336+
dict_of_typx = {'str_or_none': TypeForm(str | None)}
1337+
# Error: TypeForm containing a string annotation cannot be recognized here. Surround with TypeForm(...) to recognize. [maybe-unrecognized-str-typeform]
1338+
list_of_typx: list[TypeForm] = [dict_of_typx['str_or_none']]
1339+
1340+
Fix the error by adding ``# type: ignore[maybe-unrecognized-str-typeform]``
1341+
to the line with the string literal:
1342+
1343+
.. code-block:: python
1344+
1345+
dict_of_typx = {'str_or_none': TypeForm(str | None)}
1346+
list_of_typx: list[TypeForm] = [dict_of_typx['str_or_none']] # type: ignore[maybe-unrecognized-str-typeform]
1347+
12891348
.. _code-misc:
12901349

12911350
Miscellaneous checks [misc]

docs/source/error_code_list2.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,3 +676,26 @@ Example:
676676
print("red")
677677
case _:
678678
print("other")
679+
680+
.. _code-untyped-decorator:
681+
682+
Error if an untyped decorator makes a typed function effectively untyped [untyped-decorator]
683+
--------------------------------------------------------------------------------------------
684+
685+
If enabled with :option:`--disallow-untyped-decorators <mypy --disallow-untyped-decorators>`
686+
mypy generates an error if a typed function is wrapped by an untyped decorator
687+
(as this would effectively remove the benefits of typing the function).
688+
689+
Example:
690+
691+
.. code-block:: python
692+
693+
def printing_decorator(func):
694+
def wrapper(*args, **kwds):
695+
print("Calling", func)
696+
return func(*args, **kwds)
697+
return wrapper
698+
# A decorated function.
699+
@printing_decorator # E: Untyped decorator makes function "add_forty_two" untyped [untyped-decorator]
700+
def add_forty_two(value: int) -> int:
701+
return value + 42

docs/source/generics.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,7 @@ This example correctly uses a covariant type variable:
11651165
11661166
See :ref:`variance-of-generics` for more about variance.
11671167

1168-
Generic protocols can also be recursive. Example (Python 3.12 synta):
1168+
Generic protocols can also be recursive. Example (Python 3.12 syntax):
11691169

11701170
.. code-block:: python
11711171

docs/source/kinds_of_types.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ isn't supported by the runtime with some limitations, if you use
294294
def f(x: int | str) -> None: # OK on Python 3.7 and later
295295
...
296296
297+
.. _no-strict-optional:
297298
.. _strict_optional:
298299

299300
Optional types and the None type

0 commit comments

Comments
 (0)