Skip to content

Commit 3cf9713

Browse files
committed
Merge tag '1.7-forkpoint' into merge-1.7-fork
# Conflicts: # .github/ISSUE_TEMPLATE/feature.md # .github/workflows/test.yml # CHANGELOG.md # MANIFEST.in # mypy/checker.py # mypy/checkexpr.py # mypy/checkstrformat.py # mypy/constraints.py # mypy/errors.py # mypy/fixup.py # mypy/maptype.py # mypy/meet.py # mypy/messages.py # mypy/options.py # mypy/plugins/dataclasses.py # mypy/plugins/default.py # mypy/semanal.py # mypy/stubgen.py # mypy/subtypes.py # mypy/test/testtypes.py # mypy/types.py # mypy/typeshed/stdlib/builtins.pyi # mypy/typeshed/stdlib/importlib/machinery.pyi # mypy/typeshed/stdlib/pathlib.pyi # mypy_self_check.ini # pyproject.toml # setup.py # test-data/unit/check-expressions.test # test-data/unit/check-inference-context.test # test-data/unit/check-inference.test # test-data/unit/check-optional.test # test-data/unit/check-python310.test # test-data/unit/check-type-aliases.test # test-data/unit/check-unions.test # test-data/unit/check-varargs.test # test-data/unit/fine-grained-modules.test # test-data/unit/pythoneval.test
2 parents b47ff09 + 5624f40 commit 3cf9713

File tree

332 files changed

+13328
-4942
lines changed

Some content is hidden

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

332 files changed

+13328
-4942
lines changed

.github/ISSUE_TEMPLATE/feature.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ Before you raise this, consider if it's better suited to a discussion: https://g
88

99
<!-- Please explain why this feature is based -->
1010

11-
<!-- Please include a full usage example of this feature -->
11+
<!-- Please explain why this feature should be implemented and how it would be used. Please include a full usage example. -->

.github/workflows/build_wheels.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ on:
55
branches: [main, master, 'release*']
66
tags: ['*']
77

8+
permissions:
9+
contents: write
10+
811
jobs:
912
build-wheels:
1013
if: github.repository == 'KotlinIsland/basedmypy'
1114
runs-on: ubuntu-latest
1215
steps:
13-
- uses: actions/checkout@v3
16+
- uses: actions/checkout@v4
1417
- uses: actions/setup-python@v4
1518
with:
1619
python-version: '3.11'

.github/workflows/docs.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,23 @@ on:
88
pull_request:
99
paths:
1010
- 'docs/**'
11+
# We now have a docs check that fails if any error codes don't have documentation,
12+
# so it's important to do the docs build on all PRs touching mypy/errorcodes.py
13+
# in case somebody's adding a new error code without any docs
14+
- 'mypy/errorcodes.py'
1115
- 'mypyc/doc/**'
1216
- '**/*.rst'
1317
- '**/*.md'
1418
- CREDITS
1519
- LICENSE
1620

21+
permissions:
22+
contents: read
23+
24+
concurrency:
25+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
26+
cancel-in-progress: true
27+
1728
jobs:
1829
docs:
1930
runs-on: ubuntu-latest
@@ -22,7 +33,7 @@ jobs:
2233
TOX_SKIP_MISSING_INTERPRETERS: False
2334
VERIFY_MYPY_ERROR_CODES: 1
2435
steps:
25-
- uses: actions/checkout@v3
36+
- uses: actions/checkout@v4
2637
- uses: actions/setup-python@v4
2738
with:
2839
python-version: '3.8'

.github/workflows/mypy_primer.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ on:
1515
- 'mypy/test/**'
1616
- 'test-data/**'
1717

18+
permissions:
19+
contents: read
20+
1821
concurrency:
1922
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
2023
cancel-in-progress: true
@@ -30,7 +33,7 @@ jobs:
3033
shard-index: [0, 1, 2, 3, 4]
3134
fail-fast: false
3235
steps:
33-
- uses: actions/checkout@v3
36+
- uses: actions/checkout@v4
3437
with:
3538
path: mypy_to_test
3639
fetch-depth: 0

.github/workflows/sync_typeshed.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
if: github.repository == 'python/mypy'
1616
runs-on: ubuntu-latest
1717
steps:
18-
- uses: actions/checkout@v3
18+
- uses: actions/checkout@v4
1919
with:
2020
fetch-depth: 0
2121
# TODO: use whatever solution ends up working for

.github/workflows/test.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ on:
1515
- CREDITS
1616
- LICENSE
1717

18+
permissions:
19+
contents: read
20+
1821
concurrency:
1922
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
2023
cancel-in-progress: true
@@ -61,15 +64,15 @@ jobs:
6164
tox_extra_args: "-n 2"
6265
test_mypyc: true
6366
- name: Test suite with py312-ubuntu, mypyc-compiled
64-
python: '3.12-dev'
67+
python: '3.12'
6568
arch: x64
6669
os: ubuntu-latest
6770
toxenv: py
6871
tox_extra_args: "-n 2"
6972
test_mypyc: true
7073

71-
- name: mypyc runtime tests with py38-macos
72-
python: '3.8.17'
74+
- name: mypyc runtime tests with py39-macos
75+
python: '3.9.18'
7376
arch: x64
7477
os: macos-latest
7578
toxenv: py
@@ -112,7 +115,7 @@ jobs:
112115
# Pytest
113116
PYTEST_ADDOPTS: --color=yes
114117
steps:
115-
- uses: actions/checkout@v3
118+
- uses: actions/checkout@v4
116119
- uses: actions/setup-python@v4
117120
with:
118121
python-version: ${{ matrix.python }}
@@ -126,7 +129,7 @@ jobs:
126129
./misc/build-debug-python.sh $PYTHONVERSION $PYTHONDIR $VENV
127130
source $VENV/bin/activate
128131
- name: Install tox
129-
run: pip install --upgrade 'setuptools!=50' tox==4.11.0
132+
run: pip install setuptools==68.2.2 tox==4.11.0
130133
- name: Compiled with mypyc
131134
if: ${{ matrix.test_mypyc }}
132135
run: |
@@ -151,7 +154,7 @@ jobs:
151154
CXX: i686-linux-gnu-g++
152155
CC: i686-linux-gnu-gcc
153156
steps:
154-
- uses: actions/checkout@v3
157+
- uses: actions/checkout@v4
155158
- name: Install 32-bit build dependencies
156159
run: |
157160
sudo dpkg --add-architecture i386 && \
@@ -174,7 +177,7 @@ jobs:
174177
default: 3.11.1
175178
command: python -c "import platform; print(f'{platform.architecture()=} {platform.machine()=}');"
176179
- name: Install tox
177-
run: pip install --upgrade 'setuptools!=50' tox==4.11.0
180+
run: pip install setuptools==68.2.2 tox==4.11.0
178181
- name: Setup tox environment
179182
run: tox run -e py --notest
180183
- name: Test

.github/workflows/test_stubgenc.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,21 @@ on:
1212
- 'mypy/stubdoc.py'
1313
- 'test-data/stubgen/**'
1414

15+
permissions:
16+
contents: read
17+
18+
concurrency:
19+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
20+
cancel-in-progress: true
21+
1522
jobs:
1623
stubgenc:
1724
# Check stub file generation for a small pybind11 project
1825
# (full text match is required to pass)
1926
runs-on: ubuntu-latest
2027
steps:
2128

22-
- uses: actions/checkout@v3
29+
- uses: actions/checkout@v4
2330

2431
- name: Setup 🐍 3.8
2532
uses: actions/setup-python@v4

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
exclude: '^(mypyc/external/)|(mypy/typeshed/)' # Exclude all vendored code from lints
22
repos:
33
- repo: https://github.com/pre-commit/pre-commit-hooks
4-
rev: v4.4.0 # must match test-requirements.txt
4+
rev: v4.5.0 # must match test-requirements.txt
55
hooks:
66
- id: trailing-whitespace
77
- id: end-of-file-fixer
88
exclude: "^.mypy/baseline.json$"
99
- repo: https://github.com/psf/black-pre-commit-mirror
10-
rev: 23.7.0 # must match test-requirements.txt
10+
rev: 23.9.1 # must match test-requirements.txt
1111
hooks:
1212
- id: black
1313
- repo: https://github.com/astral-sh/ruff-pre-commit
14-
rev: v0.0.281 # must match test-requirements.txt
14+
rev: v0.1.0 # must match test-requirements.txt
1515
hooks:
1616
- id: ruff
1717
args: [--exit-non-zero-on-fix]

CONTRIBUTING.md

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,6 @@ like this:
6262
python3 runtests.py
6363
```
6464

65-
You can also use `tox` to run tests (`tox` handles setting up the test environment for you):
66-
67-
```bash
68-
tox run -e py
69-
70-
# Or some specific python version:
71-
tox run -e py39
72-
73-
# Or some specific command:
74-
tox run -e lint
75-
```
76-
7765
Some useful commands for running specific tests include:
7866

7967
```bash
@@ -95,6 +83,36 @@ python runtests.py lint
9583
For an in-depth guide on running and writing tests,
9684
see [the README in the test-data directory](test-data/unit/README.md).
9785

86+
#### Using `tox`
87+
88+
You can also use [`tox`](https://tox.wiki/en/latest/) to run tests and other commands.
89+
`tox` handles setting up test environments for you.
90+
91+
```bash
92+
# Run tests
93+
tox run -e py
94+
95+
# Run tests using some specific Python version
96+
tox run -e py311
97+
98+
# Run a specific command
99+
tox run -e lint
100+
101+
# Run a single test from the test suite
102+
tox run -e py -- -n0 -k 'test_name'
103+
104+
# Run all test cases in the "test-data/unit/check-dataclasses.test" file using
105+
# Python 3.11 specifically
106+
tox run -e py311 -- mypy/test/testcheck.py::TypeCheckSuite::check-dataclasses.test
107+
108+
# Set up a development environment with all the project libraries and run a command
109+
tox -e dev -- mypy --verbose test_case.py
110+
tox -e dev --override testenv:dev.allowlist_externals+=env -- env # inspect the environment
111+
```
112+
113+
If you don't already have `tox` installed, you can use a virtual environment as
114+
described above to install `tox` via `pip` (e.g., ``python3 -m pip install tox``).
115+
98116
## First time contributors
99117

100118
If you're looking for things to help with, browse our [issue tracker](https://github.com/python/mypy/issues)!

MANIFEST.in

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@ graft mypyc/doc
3131
# files necessary for testing sdist
3232
include mypy-requirements.txt
3333
include build-requirements.txt
34+
include test-requirements.in
3435
include test-requirements.txt
3536
include mypy_self_check.ini
3637
prune misc
37-
include misc/proper_plugin.py
3838
graft test-data
3939
include conftest.py
4040
include runtests.py
4141
include pytest.ini
4242
include tox.ini
4343

4444
include LICENSE mypyc/README.md
45-
exclude .gitmodules CONTRIBUTING.md CREDITS ROADMAP.md action.yml .editorconfig
46-
exclude mypy_self_check_strict.ini CHANGELOG.md .mypy/baseline.json
45+
exclude .gitmodules CONTRIBUTING.md CREDITS ROADMAP.md CHANGELOG.md action.yml .editorconfig
46+
exclude mypy_self_check_strict.ini .mypy/baseline.json
4747
exclude .git-blame-ignore-revs .pre-commit-config.yaml
4848

4949
global-exclude *.py[cod]

docs/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ Install Sphinx and other dependencies (i.e. theme) needed for the documentation.
1515
From the `docs` directory, use `pip`:
1616

1717
```
18-
$ pip install -r requirements-docs.txt
18+
pip install -r requirements-docs.txt
1919
```
2020

2121
Build the documentation like this:
2222

2323
```
24-
$ make html
24+
make html
2525
```
2626

2727
The built documentation will be placed in the `docs/build` directory. Open
@@ -33,13 +33,13 @@ Helpful documentation build commands
3333
Clean the documentation build:
3434

3535
```
36-
$ make clean
36+
make clean
3737
```
3838

3939
Test and check the links found in the documentation:
4040

4141
```
42-
$ make linkcheck
42+
make linkcheck
4343
```
4444

4545
Documentation on Read The Docs

docs/source/additional_features.rst

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ and :pep:`557`.
7171
Caveats/Known Issues
7272
====================
7373

74-
Some functions in the :py:mod:`dataclasses` module, such as :py:func:`~dataclasses.replace` and :py:func:`~dataclasses.asdict`,
74+
Some functions in the :py:mod:`dataclasses` module, such as :py:func:`~dataclasses.asdict`,
7575
have imprecise (too permissive) types. This will be fixed in future releases.
7676

7777
Mypy does not yet recognize aliases of :py:func:`dataclasses.dataclass <dataclasses.dataclass>`, and will
78-
probably never recognize dynamically computed decorators. The following examples
79-
do **not** work:
78+
probably never recognize dynamically computed decorators. The following example
79+
does **not** work:
8080

8181
.. code-block:: python
8282
@@ -94,16 +94,37 @@ do **not** work:
9494
"""
9595
attribute: int
9696
97-
@dataclass_wrapper
98-
class DynamicallyDecorated:
99-
"""
100-
Mypy doesn't recognize this as a dataclass because it is decorated by a
101-
function returning `dataclass` rather than by `dataclass` itself.
102-
"""
103-
attribute: int
104-
10597
AliasDecorated(attribute=1) # error: Unexpected keyword argument
106-
DynamicallyDecorated(attribute=1) # error: Unexpected keyword argument
98+
99+
100+
To have Mypy recognize a wrapper of :py:func:`dataclasses.dataclass <dataclasses.dataclass>`
101+
as a dataclass decorator, consider using the :py:func:`~typing.dataclass_transform` decorator:
102+
103+
.. code-block:: python
104+
105+
from dataclasses import dataclass, Field
106+
from typing import TypeVar, dataclass_transform
107+
108+
T = TypeVar('T')
109+
110+
@dataclass_transform(field_specifiers=(Field,))
111+
def my_dataclass(cls: type[T]) -> type[T]:
112+
...
113+
return dataclass(cls)
114+
115+
116+
Data Class Transforms
117+
*********************
118+
119+
Mypy supports the :py:func:`~typing.dataclass_transform` decorator as described in
120+
`PEP 681 <https://www.python.org/dev/peps/pep-0681/#the-dataclass-transform-decorator>`_.
121+
122+
.. note::
123+
124+
Pragmatically, mypy will assume such classes have the internal attribute :code:`__dataclass_fields__`
125+
(even though they might lack it in runtime) and will assume functions such as :py:func:`dataclasses.is_dataclass`
126+
and :py:func:`dataclasses.fields` treat them as if they were dataclasses
127+
(even though they may fail at runtime).
107128

108129
.. _attrs_package:
109130

0 commit comments

Comments
 (0)