Skip to content

Commit 04f3e08

Browse files
authored
Merge branch 'master' into checkmember-proto
2 parents 689c119 + 409d294 commit 04f3e08

File tree

350 files changed

+6967
-6488
lines changed

Some content is hidden

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

350 files changed

+6967
-6488
lines changed

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
with:
4242
python-version: '3.12'
4343
- name: Install tox
44-
run: pip install tox==4.21.2
44+
run: pip install tox==4.26.0
4545
- name: Setup tox environment
4646
run: tox run -e ${{ env.TOXENV }} --notest
4747
- name: Test

.github/workflows/test.yml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,11 @@ jobs:
4747
os: ubuntu-24.04-arm
4848
toxenv: py
4949
tox_extra_args: "-n 4"
50-
- name: Test suite with py311-ubuntu, mypyc-compiled
50+
- name: Test suite with py311-ubuntu
5151
python: '3.11'
5252
os: ubuntu-24.04-arm
5353
toxenv: py
5454
tox_extra_args: "-n 4"
55-
test_mypyc: true
5655
- name: Test suite with py312-ubuntu, mypyc-compiled
5756
python: '3.12'
5857
os: ubuntu-24.04-arm
@@ -66,13 +65,13 @@ jobs:
6665
tox_extra_args: "-n 4"
6766
test_mypyc: true
6867

69-
# - name: Test suite with py314-dev-ubuntu
70-
# python: '3.14-dev'
71-
# os: ubuntu-24.04-arm
72-
# toxenv: py
73-
# tox_extra_args: "-n 4"
74-
# allow_failure: true
75-
# test_mypyc: true
68+
- name: Test suite with py314-dev-ubuntu
69+
python: '3.14-dev'
70+
os: ubuntu-24.04-arm
71+
toxenv: py
72+
tox_extra_args: "-n 4"
73+
# allow_failure: true
74+
test_mypyc: true
7675

7776
- name: mypyc runtime tests with py39-macos
7877
python: '3.9.21'
@@ -115,6 +114,8 @@ jobs:
115114
FORCE_COLOR: ${{ !(startsWith(matrix.os, 'windows-') && startsWith(matrix.toxenv, 'py')) && 1 || 0 }}
116115
# Tox
117116
PY_COLORS: 1
117+
# Python -- Disable argparse help colors (3.14+)
118+
PYTHON_COLORS: 0
118119
# Mypy (see https://github.com/python/mypy/issues/7771)
119120
TERM: xterm-color
120121
MYPY_FORCE_COLOR: 1
@@ -167,7 +168,7 @@ jobs:
167168
echo debug build; python -c 'import sysconfig; print(bool(sysconfig.get_config_var("Py_DEBUG")))'
168169
echo os.cpu_count; python -c 'import os; print(os.cpu_count())'
169170
echo os.sched_getaffinity; python -c 'import os; print(len(getattr(os, "sched_getaffinity", lambda *args: [])(0)))'
170-
pip install setuptools==75.1.0 tox==4.21.2
171+
pip install setuptools==75.1.0 tox==4.26.0
171172
172173
- name: Compiled with mypyc
173174
if: ${{ matrix.test_mypyc }}
@@ -230,7 +231,7 @@ jobs:
230231
default: 3.11.1
231232
command: python -c "import platform; print(f'{platform.architecture()=} {platform.machine()=}');"
232233
- name: Install tox
233-
run: pip install setuptools==75.1.0 tox==4.21.2
234+
run: pip install setuptools==75.1.0 tox==4.26.0
234235
- name: Setup tox environment
235236
run: tox run -e py --notest
236237
- name: Test

CHANGELOG.md

Lines changed: 405 additions & 10 deletions
Large diffs are not rendered by default.

CONTRIBUTING.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,14 @@ python runtests.py self
7676
# or equivalently:
7777
python -m mypy --config-file mypy_self_check.ini -p mypy
7878

79-
# Run a single test from the test suite
80-
pytest -n0 -k 'test_name'
79+
# Run a single test from the test suite (uses pytest substring expression matching)
80+
python runtests.py test_name
81+
# or equivalently:
82+
pytest -n0 -k test_name
8183

8284
# Run all test cases in the "test-data/unit/check-dataclasses.test" file
85+
python runtests.py check-dataclasses.test
86+
# or equivalently:
8387
pytest mypy/test/testcheck.py::TypeCheckSuite::check-dataclasses.test
8488

8589
# Run the formatters and linters

docs/source/command_line.rst

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,12 +593,58 @@ of the above sections.
593593
This flag causes mypy to suppress errors caused by not being able to fully
594594
infer the types of global and class variables.
595595

596-
.. option:: --allow-redefinition
596+
.. option:: --allow-redefinition-new
597597

598598
By default, mypy won't allow a variable to be redefined with an
599-
unrelated type. This flag enables redefinition of a variable with an
599+
unrelated type. This *experimental* flag enables the redefinition of
600+
unannotated variables with an arbitrary type. You will also need to enable
601+
:option:`--local-partial-types <mypy --local-partial-types>`.
602+
Example:
603+
604+
.. code-block:: python
605+
606+
def maybe_convert(n: int, b: bool) -> int | str:
607+
if b:
608+
x = str(n) # Assign "str"
609+
else:
610+
x = n # Assign "int"
611+
# Type of "x" is "int | str" here.
612+
return x
613+
614+
Without the new flag, mypy only supports inferring optional types
615+
(``X | None``) from multiple assignments. With this option enabled,
616+
mypy can infer arbitrary union types.
617+
618+
This also enables an unannotated variable to have different types in different
619+
code locations:
620+
621+
.. code-block:: python
622+
623+
if check():
624+
for x in range(n):
625+
# Type of "x" is "int" here.
626+
...
627+
else:
628+
for x in ['a', 'b']:
629+
# Type of "x" is "str" here.
630+
...
631+
632+
Note: We are planning to turn this flag on by default in a future mypy
633+
release, along with :option:`--local-partial-types <mypy --local-partial-types>`.
634+
The feature is still experimental, and the semantics may still change.
635+
636+
.. option:: --allow-redefinition
637+
638+
This is an older variant of
639+
:option:`--allow-redefinition-new <mypy --allow-redefinition-new>`.
640+
This flag enables redefinition of a variable with an
600641
arbitrary type *in some contexts*: only redefinitions within the
601642
same block and nesting depth as the original definition are allowed.
643+
644+
We have no plans to remove this flag, but we expect that
645+
:option:`--allow-redefinition-new <mypy --allow-redefinition-new>`
646+
will replace this flag for new use cases eventually.
647+
602648
Example where this can be useful:
603649

604650
.. code-block:: python

docs/source/config_file.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,44 @@ section of the command line docs.
713713
Causes mypy to suppress errors caused by not being able to fully
714714
infer the types of global and class variables.
715715

716+
.. confval:: allow_redefinition_new
717+
718+
:type: boolean
719+
:default: False
720+
721+
By default, mypy won't allow a variable to be redefined with an
722+
unrelated type. This *experimental* flag enables the redefinition of
723+
unannotated variables with an arbitrary type. You will also need to enable
724+
:confval:`local_partial_types`.
725+
Example:
726+
727+
.. code-block:: python
728+
729+
def maybe_convert(n: int, b: bool) -> int | str:
730+
if b:
731+
x = str(n) # Assign "str"
732+
else:
733+
x = n # Assign "int"
734+
# Type of "x" is "int | str" here.
735+
return x
736+
737+
This also enables an unannotated variable to have different types in different
738+
code locations:
739+
740+
.. code-block:: python
741+
742+
if check():
743+
for x in range(n):
744+
# Type of "x" is "int" here.
745+
...
746+
else:
747+
for x in ['a', 'b']:
748+
# Type of "x" is "str" here.
749+
...
750+
751+
Note: We are planning to turn this flag on by default in a future mypy
752+
release, along with :confval:`local_partial_types`.
753+
716754
.. confval:: allow_redefinition
717755

718756
:type: boolean
@@ -746,6 +784,7 @@ section of the command line docs.
746784

747785
Disallows inferring variable type for ``None`` from two assignments in different scopes.
748786
This is always implicitly enabled when using the :ref:`mypy daemon <mypy_daemon>`.
787+
This will be enabled by default in a future mypy release.
749788

750789
.. confval:: disable_error_code
751790

docs/source/generics.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Using ``Stack`` is similar to built-in container types:
9393
stack.push('x')
9494
9595
stack2: Stack[str] = Stack()
96-
stack2.append('x')
96+
stack2.push('x')
9797
9898
Construction of instances of generic types is type checked (Python 3.12 syntax):
9999

0 commit comments

Comments
 (0)