Skip to content

Commit 84c06a6

Browse files
authored
Merge branch 'master' into f/typeform3
2 parents 170a5e7 + 7b4f631 commit 84c06a6

File tree

214 files changed

+10240
-2664
lines changed

Some content is hidden

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

214 files changed

+10240
-2664
lines changed

.github/workflows/test.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
# the oldest and newest supported Python versions
3434
- name: Test suite with py39-ubuntu, mypyc-compiled
3535
python: '3.9'
36-
os: ubuntu-22.04-arm
36+
os: ubuntu-24.04-arm
3737
toxenv: py
3838
tox_extra_args: "-n 4"
3939
test_mypyc: true
@@ -44,31 +44,31 @@ jobs:
4444
tox_extra_args: "-n 4"
4545
- name: Test suite with py310-ubuntu
4646
python: '3.10'
47-
os: ubuntu-22.04-arm
47+
os: ubuntu-24.04-arm
4848
toxenv: py
4949
tox_extra_args: "-n 4"
5050
- name: Test suite with py311-ubuntu, mypyc-compiled
5151
python: '3.11'
52-
os: ubuntu-22.04-arm
52+
os: ubuntu-24.04-arm
5353
toxenv: py
5454
tox_extra_args: "-n 4"
5555
test_mypyc: true
5656
- name: Test suite with py312-ubuntu, mypyc-compiled
5757
python: '3.12'
58-
os: ubuntu-22.04-arm
58+
os: ubuntu-24.04-arm
5959
toxenv: py
6060
tox_extra_args: "-n 4"
6161
test_mypyc: true
6262
- name: Test suite with py313-ubuntu, mypyc-compiled
6363
python: '3.13'
64-
os: ubuntu-22.04-arm
64+
os: ubuntu-24.04-arm
6565
toxenv: py
6666
tox_extra_args: "-n 4"
6767
test_mypyc: true
6868

6969
# - name: Test suite with py314-dev-ubuntu
7070
# python: '3.14-dev'
71-
# os: ubuntu-22.04-arm
71+
# os: ubuntu-24.04-arm
7272
# toxenv: py
7373
# tox_extra_args: "-n 4"
7474
# allow_failure: true
@@ -167,7 +167,7 @@ jobs:
167167
echo debug build; python -c 'import sysconfig; print(bool(sysconfig.get_config_var("Py_DEBUG")))'
168168
echo os.cpu_count; python -c 'import os; print(os.cpu_count())'
169169
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
170+
pip install tox==4.21.2
171171
172172
- name: Compiled with mypyc
173173
if: ${{ matrix.test_mypyc }}
@@ -230,7 +230,7 @@ jobs:
230230
default: 3.11.1
231231
command: python -c "import platform; print(f'{platform.architecture()=} {platform.machine()=}');"
232232
- name: Install tox
233-
run: pip install setuptools==75.1.0 tox==4.21.2
233+
run: pip install tox==4.21.2
234234
- name: Setup tox environment
235235
run: tox run -e py --notest
236236
- name: Test

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ repos:
1111
- id: black
1212
exclude: '^(test-data/)'
1313
- repo: https://github.com/astral-sh/ruff-pre-commit
14-
rev: v0.8.6
14+
rev: v0.11.4
1515
hooks:
1616
- id: ruff
1717
args: [--exit-non-zero-on-fix]
1818
- repo: https://github.com/python-jsonschema/check-jsonschema
19-
rev: 0.31.0
19+
rev: 0.32.1
2020
hooks:
2121
- id: check-github-workflows
2222
- id: check-github-actions
@@ -43,7 +43,7 @@ repos:
4343
# but the integration only works if shellcheck is installed
4444
- "github.com/wasilibs/go-shellcheck/cmd/[email protected]"
4545
- repo: https://github.com/woodruffw/zizmor-pre-commit
46-
rev: v1.0.1
46+
rev: v1.5.2
4747
hooks:
4848
- id: zizmor
4949
- repo: local

CREDITS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Dropbox core team:
1515

1616
Non-Dropbox core team members:
1717

18-
Ethan Smith
18+
Emma Harper Smith <[email protected]>
1919
Guido van Rossum <[email protected]>
2020
Jelle Zijlstra <[email protected]>
2121
Michael J. Sullivan <[email protected]>

docs/source/command_line.rst

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ for full details, see :ref:`running-mypy`.
8181
never recursively discover files with extensions other than ``.py`` or
8282
``.pyi``.
8383

84+
.. option:: --exclude-gitignore
85+
86+
This flag will add everything that matches ``.gitignore`` file(s) to :option:`--exclude`.
87+
8488

8589
Optional arguments
8690
******************
@@ -745,8 +749,19 @@ of the above sections.
745749

746750
.. option:: --strict
747751

748-
This flag mode enables all optional error checking flags. You can see the
749-
list of flags enabled by strict mode in the full :option:`mypy --help` output.
752+
This flag mode enables a defined subset of optional error-checking flags.
753+
This subset primarily includes checks for inadvertent type unsoundness (i.e
754+
strict will catch type errors as long as intentional methods like type ignore
755+
or casting were not used.)
756+
757+
Note: the :option:`--warn-unreachable` flag
758+
is not automatically enabled by the strict flag.
759+
760+
The strict flag does not take precedence over other strict-related flags.
761+
Directly specifying a flag of alternate behavior will override the
762+
behavior of strict, regardless of the order in which they are passed.
763+
You can see the list of flags enabled by strict mode in the full
764+
:option:`mypy --help` output.
750765

751766
Note: the exact list of flags enabled by running :option:`--strict` may change
752767
over time.

docs/source/config_file.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,14 @@ section of the command line docs.
288288
289289
See :ref:`using-a-pyproject-toml`.
290290

291+
.. confval:: exclude_gitignore
292+
293+
:type: boolean
294+
:default: False
295+
296+
This flag will add everything that matches ``.gitignore`` file(s) to :confval:`exclude`.
297+
This option may only be set in the global section (``[mypy]``).
298+
291299
.. confval:: namespace_packages
292300

293301
:type: boolean
@@ -424,7 +432,7 @@ Platform configuration
424432

425433
Specifies the Python version used to parse and check the target
426434
program. The string should be in the format ``MAJOR.MINOR`` --
427-
for example ``2.7``. The default is the version of the Python
435+
for example ``3.9``. The default is the version of the Python
428436
interpreter used to run mypy.
429437

430438
This option may only be set in the global section (``[mypy]``).
@@ -1188,7 +1196,7 @@ of your repo (or append it to the end of an existing ``pyproject.toml`` file) an
11881196
# mypy global options:
11891197
11901198
[tool.mypy]
1191-
python_version = "2.7"
1199+
python_version = "3.9"
11921200
warn_return_any = true
11931201
warn_unused_configs = true
11941202
exclude = [

docs/source/metaclasses.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ Mypy supports the lookup of attributes in the metaclass:
3434

3535
.. code-block:: python
3636
37-
from typing import ClassVar, Self
37+
from typing import ClassVar, TypeVar
38+
39+
S = TypeVar("S")
3840
3941
class M(type):
4042
count: ClassVar[int] = 0
4143
42-
def make(cls) -> Self:
44+
def make(cls: type[S]) -> S:
4345
M.count += 1
4446
return cls()
4547
@@ -55,9 +57,6 @@ Mypy supports the lookup of attributes in the metaclass:
5557
b: B = B.make() # metaclasses are inherited
5658
print(B.count + " objects were created") # Error: Unsupported operand types for + ("int" and "str")
5759
58-
.. note::
59-
In Python 3.10 and earlier, ``Self`` is available in ``typing_extensions``.
60-
6160
.. _limitations:
6261

6362
Gotchas and limitations of metaclass support
@@ -88,3 +87,6 @@ so it's better not to combine metaclasses and class hierarchies:
8887
such as ``class A(metaclass=f()): ...``
8988
* Mypy does not and cannot understand arbitrary metaclass code.
9089
* Mypy only recognizes subclasses of :py:class:`type` as potential metaclasses.
90+
* ``Self`` is not allowed as annotation in metaclasses as per `PEP 673`_.
91+
92+
.. _PEP 673: https://peps.python.org/pep-0673/#valid-locations-for-self

docs/source/runtime_troubles.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ version of Python considers legal code. This section describes these scenarios
88
and explains how to get your code running again. Generally speaking, we have
99
three tools at our disposal:
1010

11-
* Use of ``from __future__ import annotations`` (:pep:`563`)
12-
(this behaviour may eventually be made the default in a future Python version)
1311
* Use of string literal types or type comments
1412
* Use of ``typing.TYPE_CHECKING``
13+
* Use of ``from __future__ import annotations`` (:pep:`563`)
1514

1615
We provide a description of these before moving onto discussion of specific
1716
problems you may encounter.

docs/source/type_narrowing.rst

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ techniques which are supported by mypy.
88

99
Type narrowing is when you convince a type checker that a broader type is actually more specific, for instance, that an object of type ``Shape`` is actually of the narrower type ``Square``.
1010

11+
The following type narrowing techniques are available:
12+
13+
- :ref:`type-narrowing-expressions`
14+
- :ref:`casts`
15+
- :ref:`type-guards`
16+
- :ref:`typeis`
17+
18+
19+
.. _type-narrowing-expressions:
1120

1221
Type narrowing expressions
1322
--------------------------
@@ -356,40 +365,6 @@ What happens here?
356365

357366
The same will work with ``isinstance(x := a, float)`` as well.
358367

359-
Limitations
360-
-----------
361-
362-
Mypy's analysis is limited to individual symbols and it will not track
363-
relationships between symbols. For example, in the following code
364-
it's easy to deduce that if :code:`a` is None then :code:`b` must not be,
365-
therefore :code:`a or b` will always be an instance of :code:`C`,
366-
but Mypy will not be able to tell that:
367-
368-
.. code-block:: python
369-
370-
class C:
371-
pass
372-
373-
def f(a: C | None, b: C | None) -> C:
374-
if a is not None or b is not None:
375-
return a or b # Incompatible return value type (got "C | None", expected "C")
376-
return C()
377-
378-
Tracking these sort of cross-variable conditions in a type checker would add significant complexity
379-
and performance overhead.
380-
381-
You can use an ``assert`` to convince the type checker, override it with a :ref:`cast <casts>`
382-
or rewrite the function to be slightly more verbose:
383-
384-
.. code-block:: python
385-
386-
def f(a: C | None, b: C | None) -> C:
387-
if a is not None:
388-
return a
389-
elif b is not None:
390-
return b
391-
return C()
392-
393368

394369
.. _typeis:
395370

@@ -555,3 +530,38 @@ You can use the assignment expression operator ``:=`` with ``TypeIs`` to create
555530
reveal_type(x) # Revealed type is 'float'
556531
# x is narrowed to float in this block
557532
print(x + 1.0)
533+
534+
535+
Limitations
536+
-----------
537+
538+
Mypy's analysis is limited to individual symbols and it will not track
539+
relationships between symbols. For example, in the following code
540+
it's easy to deduce that if :code:`a` is None then :code:`b` must not be,
541+
therefore :code:`a or b` will always be an instance of :code:`C`,
542+
but Mypy will not be able to tell that:
543+
544+
.. code-block:: python
545+
546+
class C:
547+
pass
548+
549+
def f(a: C | None, b: C | None) -> C:
550+
if a is not None or b is not None:
551+
return a or b # Incompatible return value type (got "C | None", expected "C")
552+
return C()
553+
554+
Tracking these sort of cross-variable conditions in a type checker would add significant complexity
555+
and performance overhead.
556+
557+
You can use an ``assert`` to convince the type checker, override it with a :ref:`cast <casts>`
558+
or rewrite the function to be slightly more verbose:
559+
560+
.. code-block:: python
561+
562+
def f(a: C | None, b: C | None) -> C:
563+
if a is not None:
564+
return a
565+
elif b is not None:
566+
return b
567+
return C()

mypy-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
# and the pins in setup.py
33
typing_extensions>=4.6.0
44
mypy_extensions>=1.0.0
5+
pathspec>=0.9.0
56
tomli>=1.1.0; python_version<'3.11'

mypy/argmap.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,8 @@ def expand_actual_type(
249249
formal_name = (set(actual_type.items.keys()) - self.kwargs_used).pop()
250250
self.kwargs_used.add(formal_name)
251251
return actual_type.items[formal_name]
252-
elif (
253-
isinstance(actual_type, Instance)
254-
and len(actual_type.args) > 1
255-
and is_subtype(actual_type, self.context.mapping_type)
252+
elif isinstance(actual_type, Instance) and is_subtype(
253+
actual_type, self.context.mapping_type
256254
):
257255
# Only `Mapping` type can be unpacked with `**`.
258256
# Other types will produce an error somewhere else.

0 commit comments

Comments
 (0)