Skip to content

Commit 07cfe7b

Browse files
committed
Merge remote-tracking branch 'origin/master' into gcndb
2 parents 47b820c + 78339b9 commit 07cfe7b

File tree

396 files changed

+12617
-5061
lines changed

Some content is hidden

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

396 files changed

+12617
-5061
lines changed

.git-blame-ignore-revs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,7 @@
22
97c5ee99bc98dc475512e549b252b23a6e7e0997
33
# Use builtin generics and PEP 604 for type annotations wherever possible (#13427)
44
23ee1e7aff357e656e3102435ad0fe3b5074571e
5+
# Use variable annotations (#10723)
6+
f98f78216ba9d6ab68c8e69c19e9f3c7926c5efe
7+
# run pyupgrade (#12711)
8+
fc335cb16315964b923eb1927e3aad1516891c28

.github/ISSUE_TEMPLATE/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ contact_links:
22
- about: "Please check the linked documentation page before filing new issues."
33
name: "Common issues and solutions"
44
url: "https://mypy.readthedocs.io/en/stable/common_issues.html"
5-
- about: "Please ask and answer any questions on the mypy Gitter."
5+
- about: "Please ask and answer any questions on the python/typing Gitter."
66
name: "Questions or Chat"
77
url: "https://gitter.im/python/typing"

.github/workflows/build_wheels.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- uses: actions/checkout@v3
1414
- uses: actions/setup-python@v4
1515
with:
16-
python-version: '3.7'
16+
python-version: '3.11'
1717
- name: Trigger script
1818
env:
1919
WHEELS_PUSH_TOKEN: ${{ secrets.WHEELS_PUSH_TOKEN }}

.github/workflows/docs.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ jobs:
2020
env:
2121
TOXENV: docs
2222
TOX_SKIP_MISSING_INTERPRETERS: False
23+
VERIFY_MYPY_ERROR_CODES: 1
2324
steps:
2425
- uses: actions/checkout@v3
2526
- uses: actions/setup-python@v4
2627
with:
27-
python-version: '3.7'
28+
python-version: '3.8'
2829
- name: Install tox
2930
run: pip install --upgrade 'setuptools!=50' tox==4.4.4
3031
- name: Setup tox environment

.github/workflows/test.yml

Lines changed: 28 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -26,77 +26,77 @@ jobs:
2626
fail-fast: false
2727
matrix:
2828
include:
29-
- name: Test suite with py37-windows-64
30-
python: '3.7'
31-
arch: x64
32-
os: windows-latest
33-
toxenv: py37
34-
- name: Test suite with py38-ubuntu
29+
# Make sure to run mypyc compiled unit tests for both
30+
# the oldest and newest supported Python versions
31+
- name: Test suite with py38-ubuntu, mypyc-compiled
3532
python: '3.8'
3633
arch: x64
3734
os: ubuntu-latest
3835
toxenv: py
3936
tox_extra_args: "-n 2"
40-
- name: Test suite with py39-ubuntu
41-
python: '3.9'
37+
test_mypyc: true
38+
- name: Test suite with py38-windows-64
39+
python: '3.8'
4240
arch: x64
43-
os: ubuntu-latest
44-
toxenv: py
41+
os: windows-latest
42+
toxenv: py38
4543
tox_extra_args: "-n 2"
46-
- name: Test suite with py37-ubuntu, mypyc-compiled
47-
python: '3.7'
44+
- name: Test suite with py39-ubuntu
45+
python: '3.9'
4846
arch: x64
4947
os: ubuntu-latest
5048
toxenv: py
5149
tox_extra_args: "-n 2"
52-
test_mypyc: true
53-
- name: Test suite with py310-ubuntu, mypyc-compiled
50+
- name: Test suite with py310-ubuntu
5451
python: '3.10'
5552
arch: x64
5653
os: ubuntu-latest
5754
toxenv: py
5855
tox_extra_args: "-n 2"
59-
test_mypyc: true
60-
- name: Test suite with py310-ubuntu
61-
python: '3.10'
56+
- name: Test suite with py311-ubuntu, mypyc-compiled
57+
python: '3.11'
6258
arch: x64
6359
os: ubuntu-latest
6460
toxenv: py
6561
tox_extra_args: "-n 2"
66-
- name: Test suite with py311-ubuntu, mypyc-compiled
67-
python: '3.11'
62+
test_mypyc: true
63+
- name: Test suite with py312-ubuntu, mypyc-compiled
64+
python: '3.12-dev'
6865
arch: x64
6966
os: ubuntu-latest
7067
toxenv: py
7168
tox_extra_args: "-n 2"
7269
test_mypyc: true
73-
- name: mypyc runtime tests with py37-macos
74-
python: '3.7'
70+
71+
- name: mypyc runtime tests with py38-macos
72+
python: '3.8.17'
7573
arch: x64
7674
os: macos-latest
7775
toxenv: py
7876
tox_extra_args: "-n 2 mypyc/test/test_run.py mypyc/test/test_external.py"
79-
- name: mypyc runtime tests with py37-debug-build-ubuntu
80-
python: '3.7.13'
77+
- name: mypyc runtime tests with py38-debug-build-ubuntu
78+
python: '3.8.17'
8179
arch: x64
8280
os: ubuntu-latest
8381
toxenv: py
8482
tox_extra_args: "-n 2 mypyc/test/test_run.py mypyc/test/test_external.py"
8583
debug_build: true
86-
- name: Type check our own code (py37-ubuntu)
87-
python: '3.7'
84+
85+
- name: Type check our own code (py38-ubuntu)
86+
python: '3.8'
8887
arch: x64
8988
os: ubuntu-latest
9089
toxenv: type
91-
- name: Type check our own code (py37-windows-64)
92-
python: '3.7'
90+
- name: Type check our own code (py38-windows-64)
91+
python: '3.8'
9392
arch: x64
9493
os: windows-latest
9594
toxenv: type
95+
9696
# We also run these checks with pre-commit in CI,
9797
# but it's useful to run them with tox too,
9898
# to ensure the tox env works as expected
99-
- name: Formatting with Black + isort and code style with flake8
99+
- name: Formatting and code style with Black + ruff
100100
python: '3.10'
101101
arch: x64
102102
os: ubuntu-latest
@@ -141,24 +141,6 @@ jobs:
141141
- name: Test
142142
run: tox run -e ${{ matrix.toxenv }} --skip-pkg-install -- ${{ matrix.tox_extra_args }}
143143

144-
python-nightly:
145-
runs-on: ubuntu-latest
146-
name: Test suite with Python nightly
147-
steps:
148-
- uses: actions/checkout@v3
149-
- uses: actions/setup-python@v4
150-
with:
151-
python-version: '3.12-dev'
152-
- name: Install tox
153-
run: pip install --upgrade 'setuptools!=50' tox==4.4.4
154-
- name: Setup tox environment
155-
run: tox run -e py --notest
156-
- name: Test
157-
run: tox run -e py --skip-pkg-install -- "-n 2"
158-
continue-on-error: true
159-
- name: Mark as a success
160-
run: exit 0
161-
162144
python_32bits:
163145
runs-on: ubuntu-latest
164146
name: Test mypyc suite with 32-bit Python

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,5 @@ test_capi
5757
*.o
5858
*.a
5959
test_capi
60-
/.mypyc-flake8-cache.json
6160
/mypyc/lib-rt/build/
6261
/mypyc/lib-rt/*.so

.pre-commit-config.yaml

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,14 @@ repos:
55
hooks:
66
- id: trailing-whitespace
77
- id: end-of-file-fixer
8-
- repo: https://github.com/psf/black
9-
rev: 23.3.0 # must match test-requirements.txt
8+
- repo: https://github.com/psf/black-pre-commit-mirror
9+
rev: 23.7.0 # must match test-requirements.txt
1010
hooks:
1111
- id: black
12-
- repo: https://github.com/pycqa/isort
13-
rev: 5.12.0 # must match test-requirements.txt
12+
- repo: https://github.com/astral-sh/ruff-pre-commit
13+
rev: v0.0.280 # must match test-requirements.txt
1414
hooks:
15-
- id: isort
16-
- repo: https://github.com/pycqa/flake8
17-
rev: 6.0.0 # must match test-requirements.txt
18-
hooks:
19-
- id: flake8
20-
additional_dependencies:
21-
- flake8-bugbear==23.3.23 # must match test-requirements.txt
22-
- flake8-noqa==1.3.1 # must match test-requirements.txt
23-
15+
- id: ruff
16+
args: [--exit-non-zero-on-fix]
2417
ci:
25-
# We run flake8 as part of our GitHub Actions suite in CI
26-
skip: [flake8]
18+
autoupdate_schedule: quarterly

.readthedocs.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Read the Docs configuration file
2+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
3+
4+
version: 2
5+
6+
build:
7+
os: ubuntu-22.04
8+
tools:
9+
python: "3.11"
10+
11+
sphinx:
12+
configuration: docs/source/conf.py
13+
14+
formats: [pdf, htmlzip, epub]
15+
16+
python:
17+
install:
18+
- requirements: docs/requirements-docs.txt

CONTRIBUTING.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,8 @@ pytest -n0 -k 'test_name'
8888
# Run all test cases in the "test-data/unit/check-dataclasses.test" file
8989
pytest mypy/test/testcheck.py::TypeCheckSuite::check-dataclasses.test
9090

91-
# Run the linter
92-
flake8
93-
94-
# Run formatters
95-
black . && isort .
91+
# Run the formatters and linters
92+
python runtests.py lint
9693
```
9794

9895
For an in-depth guide on running and writing tests,
@@ -154,10 +151,6 @@ advice about good pull requests for open-source projects applies; we
154151
have [our own writeup](https://github.com/python/mypy/wiki/Good-Pull-Request)
155152
of this advice.
156153

157-
We are using `black` and `isort` to enforce a consistent coding style.
158-
Run `black . && isort .` before your commits, otherwise you would receive
159-
a CI failure.
160-
161154
Also, do not squash your commits after you have submitted a pull request, as this
162155
erases context during review. We will squash commits when the pull request is merged.
163156

LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Mypy (and mypyc) are licensed under the terms of the MIT license, reproduced bel
44

55
The MIT License
66

7-
Copyright (c) 2012-2022 Jukka Lehtosalo and contributors
8-
Copyright (c) 2015-2022 Dropbox, Inc.
7+
Copyright (c) 2012-2023 Jukka Lehtosalo and contributors
8+
Copyright (c) 2015-2023 Dropbox, Inc.
99

1010
Permission is hereby granted, free of charge, to any person obtaining a
1111
copy of this software and associated documentation files (the "Software"),

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Mypy: Static Typing for Python
1010
[![Chat at https://gitter.im/python/typing](https://badges.gitter.im/python/typing.svg)](https://gitter.im/python/typing?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
1111
[![Checked with mypy](https://www.mypy-lang.org/static/mypy_badge.svg)](https://mypy-lang.org/)
1212
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
13-
[![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/)
13+
[![Linting: Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
1414

1515
Got a question?
1616
---------------

build-requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
-r mypy-requirements.txt
33
types-psutil
44
types-setuptools
5-
types-typed-ast>=1.5.8.5,<1.6.0

docs/source/additional_features.rst

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ of the previous sections.
99
Dataclasses
1010
***********
1111

12-
In Python 3.7, a new :py:mod:`dataclasses` module has been added to the standard library.
13-
This module allows defining and customizing simple boilerplate-free classes.
14-
They can be defined using the :py:func:`@dataclasses.dataclass
15-
<python:dataclasses.dataclass>` decorator:
12+
The :py:mod:`dataclasses` module allows defining and customizing simple
13+
boilerplate-free classes. They can be defined using the
14+
:py:func:`@dataclasses.dataclass <python:dataclasses.dataclass>` decorator:
1615

1716
.. code-block:: python
1817

docs/source/cheat_sheet_py3.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ Functions
104104
print(value + "!" * excitement)
105105
106106
# Note that arguments without a type are dynamically typed (treated as Any)
107-
# and that functions without any annotations not checked
107+
# and that functions without any annotations are not checked
108108
def untyped(x):
109109
x.anything() + 1 + "string" # no errors
110110
@@ -178,8 +178,6 @@ Classes
178178
class AuditedBankAccount(BankAccount):
179179
# You can optionally declare instance variables in the class body
180180
audit_log: list[str]
181-
# This is an instance variable with a default value
182-
auditor_name: str = "The Spanish Inquisition"
183181
184182
def __init__(self, account_name: str, initial_balance: int = 0) -> None:
185183
super().__init__(account_name, initial_balance)

docs/source/class_basics.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,9 @@ override has a compatible signature:
210210

211211
In order to ensure that your code remains correct when renaming methods,
212212
it can be helpful to explicitly mark a method as overriding a base
213-
method. This can be done with the ``@override`` decorator. If the base
213+
method. This can be done with the ``@override`` decorator. ``@override``
214+
can be imported from ``typing`` starting with Python 3.12 or from
215+
``typing_extensions`` for use with older Python versions. If the base
214216
method is then renamed while the overriding method is not, mypy will
215217
show an error:
216218

@@ -233,6 +235,11 @@ show an error:
233235
def g(self, y: str) -> None: # Error: no corresponding base method found
234236
...
235237
238+
.. note::
239+
240+
Use :ref:`--enable-error-code explicit-override <code-explicit-override>` to require
241+
that method overrides use the ``@override`` decorator. Emit an error if it is missing.
242+
236243
You can also override a statically typed method with a dynamically
237244
typed one. This allows dynamically typed code to override methods
238245
defined in library classes without worrying about their type

docs/source/command_line.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,34 @@ of the above sections.
612612
613613
assert text is not None # OK, check against None is allowed as a special case.
614614
615+
.. option:: --extra-checks
616+
617+
This flag enables additional checks that are technically correct but may be
618+
impractical in real code. In particular, it prohibits partial overlap in
619+
``TypedDict`` updates, and makes arguments prepended via ``Concatenate``
620+
positional-only. For example:
621+
622+
.. code-block:: python
623+
624+
from typing import TypedDict
625+
626+
class Foo(TypedDict):
627+
a: int
628+
629+
class Bar(TypedDict):
630+
a: int
631+
b: int
632+
633+
def test(foo: Foo, bar: Bar) -> None:
634+
# This is technically unsafe since foo can have a subtype of Foo at
635+
# runtime, where type of key "b" is incompatible with int, see below
636+
bar.update(foo)
637+
638+
class Bad(Foo):
639+
b: str
640+
bad: Bad = {"a": 0, "b": "no"}
641+
test(bad, bar)
642+
615643
.. option:: --strict
616644

617645
This flag mode enables all optional error checking flags. You can see the

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
# Add any Sphinx extension module names here, as strings. They can be
3636
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3737
# ones.
38-
extensions = ["sphinx.ext.intersphinx"]
38+
extensions = ["sphinx.ext.intersphinx", "docs.source.html_builder"]
3939

4040
# Add any paths that contain templates here, relative to this directory.
4141
templates_path = ["_templates"]

docs/source/config_file.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ section of the command line docs.
366366

367367
.. confval:: no_site_packages
368368

369-
:type: bool
369+
:type: boolean
370370
:default: False
371371

372372
Disables using type information in installed packages (see :pep:`561`).

0 commit comments

Comments
 (0)