Skip to content

Commit 22aab34

Browse files
authored
Merge branch 'master' into class-constraint-tuple-tests
2 parents 2e95dbd + cf7495f commit 22aab34

File tree

173 files changed

+8001
-1423
lines changed

Some content is hidden

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

173 files changed

+8001
-1423
lines changed

.github/workflows/mypy_primer.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ on:
1313
- 'mypy/stubgen.py'
1414
- 'mypy/stubgenc.py'
1515
- 'mypy/test/**'
16-
- 'scripts/**'
1716
- 'test-data/**'
1817

1918
jobs:
@@ -24,7 +23,7 @@ jobs:
2423
contents: read
2524
strategy:
2625
matrix:
27-
shard-index: [0, 1, 2]
26+
shard-index: [0, 1, 2, 3, 4]
2827
fail-fast: false
2928
steps:
3029
- uses: actions/checkout@v3
@@ -57,7 +56,7 @@ jobs:
5756
mypy_primer \
5857
--repo mypy_to_test \
5958
--new $GITHUB_SHA --old base_commit \
60-
--num-shards 3 --shard-index ${{ matrix.shard-index }} \
59+
--num-shards 5 --shard-index ${{ matrix.shard-index }} \
6160
--debug \
6261
--output concise \
6362
| tee diff_${{ matrix.shard-index }}.txt

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ repos:
88
hooks:
99
- id: isort
1010
- repo: https://github.com/pycqa/flake8
11-
rev: 3.9.2 # must match test-requirements.txt
11+
rev: 5.0.4 # must match test-requirements.txt
1212
hooks:
1313
- id: flake8
1414
additional_dependencies:
15-
- flake8-bugbear==22.7.1 # must match test-requirements.txt
16-
- flake8-noqa==1.2.8 # must match test-requirements.txt
15+
- flake8-bugbear==22.8.23 # must match test-requirements.txt
16+
- flake8-noqa==1.2.9 # must match test-requirements.txt

CONTRIBUTING.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,16 @@ python3 runtests.py
5454
You can also use `tox` to run tests (`tox` handles setting up the test environment for you):
5555
```
5656
tox -e py
57+
58+
# Or some specific python version:
59+
tox -e py39
60+
61+
# Or some specific command:
62+
tox -e lint
5763
```
5864

5965
Some useful commands for running specific tests include:
60-
```
66+
```bash
6167
# Use mypy to check mypy's own code
6268
python3 runtests.py self
6369
# or equivalently:

build-requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
-r mypy-requirements.txt
2+
types-psutil
23
types-setuptools
3-
types-typed-ast>=1.5.0,<1.6.0
4+
types-typed-ast>=1.5.8,<1.6.0

docs/source/cheat_sheet_py3.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ Python 3 supports an annotation syntax for function declarations.
119119
sender: str,
120120
cc: Optional[list[str]],
121121
bcc: Optional[list[str]],
122-
subject='',
122+
subject: str = '',
123123
body: Optional[list[str]] = None
124124
) -> bool:
125125
...

docs/source/command_line.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,8 @@ in developing or debugging mypy internals.
830830
submitting them upstream, but also allows you to use a forked version of
831831
typeshed.
832832

833-
Note that this doesn't affect third-party library stubs.
833+
Note that this doesn't affect third-party library stubs. To test third-party stubs,
834+
for example try ``MYPYPATH=stubs/six mypy ...``.
834835

835836
.. _warn-incomplete-stub:
836837

docs/source/common_issues.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,13 @@ Ignoring a whole file
187187
---------------------
188188

189189
A ``# type: ignore`` comment at the top of a module (before any statements,
190-
including imports or docstrings) has the effect of ignoring the *entire* module.
190+
including imports or docstrings) has the effect of ignoring the entire contents of the module.
191+
192+
To only ignore errors, use a top-level ``# mypy: ignore-errors`` comment instead.
193+
To only ignore errors with a specific error code, use a top-level
194+
``# mypy: disable-error-code=...`` comment.
195+
To replace the contents of the module with ``Any``, use a per-module ``follow_imports = skip``.
196+
See :ref:`Following imports <follow-imports>` for details.
191197

192198
.. code-block:: python
193199

docs/source/config_file.rst

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -574,14 +574,6 @@ Suppressing errors
574574
Note: these configuration options are available in the config file only. There is
575575
no analog available via the command line options.
576576

577-
.. confval:: show_none_errors
578-
579-
:type: boolean
580-
:default: True
581-
582-
Shows errors related to strict ``None`` checking, if the global :confval:`strict_optional`
583-
flag is enabled.
584-
585577
.. confval:: ignore_errors
586578

587579
:type: boolean
@@ -858,9 +850,16 @@ These options may only be set in the global section (``[mypy]``).
858850

859851
:type: string
860852

861-
Specifies an alternative directory to look for stubs instead of the
862-
default ``typeshed`` directory. User home directory and environment
863-
variables will be expanded.
853+
This specifies the directory where mypy looks for standard library typeshed
854+
stubs, instead of the typeshed that ships with mypy. This is
855+
primarily intended to make it easier to test typeshed changes before
856+
submitting them upstream, but also allows you to use a forked version of
857+
typeshed.
858+
859+
User home directory and environment variables will be expanded.
860+
861+
Note that this doesn't affect third-party library stubs. To test third-party stubs,
862+
for example try ``MYPYPATH=stubs/six mypy ...``.
864863

865864
.. confval:: warn_incomplete_stub
866865

docs/source/error_codes.rst

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,47 @@ which enables the ``no-untyped-def`` error code.
6969
You can use :option:`--enable-error-code <mypy --enable-error-code>` to
7070
enable specific error codes that don't have a dedicated command-line
7171
flag or config file setting.
72+
73+
Per-module enabling/disabling error codes
74+
-----------------------------------------
75+
76+
You can use :ref:`configuration file <config-file>` sections to enable or
77+
disable specific error codes only in some modules. For example, this ``mypy.ini``
78+
config will enable non-annotated empty containers in tests, while keeping
79+
other parts of code checked in strict mode:
80+
81+
.. code-block:: ini
82+
83+
[mypy]
84+
strict = True
85+
86+
[mypy-tests.*]
87+
allow_untyped_defs = True
88+
allow_untyped_calls = True
89+
disable_error_code = var-annotated, has-type
90+
91+
Note that per-module enabling/disabling acts as override over the global
92+
options. So that you don't need to repeat the error code lists for each
93+
module if you have them in global config section. For example:
94+
95+
.. code-block:: ini
96+
97+
[mypy]
98+
enable_error_code = truthy-bool, ignore-without-code, unused-awaitable
99+
100+
[mypy-extensions.*]
101+
disable_error_code = unused-awaitable
102+
103+
The above config will allow unused awaitables in extension modules, but will
104+
still keep the other two error codes enabled. The overall logic is following:
105+
106+
* Command line and/or config main section set global error codes
107+
108+
* Individual config sections *adjust* them per glob/module
109+
110+
* Inline ``# mypy: ...`` comments can further *adjust* them for a specific
111+
module
112+
113+
So one can e.g. enable some code globally, disable it for all tests in
114+
the corresponding config section, and then re-enable it with an inline
115+
comment in some specific test.

misc/actions_stubs.py

Lines changed: 0 additions & 157 deletions
This file was deleted.

misc/analyze_cache.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __init__(
3030
self.meta_size = meta_size
3131

3232
@property
33-
def total_size(self):
33+
def total_size(self) -> int:
3434
return self.data_size + self.meta_size
3535

3636

@@ -75,7 +75,7 @@ def pluck(name: str, chunks: Iterable[JsonDict]) -> Iterable[JsonDict]:
7575
return (chunk for chunk in chunks if chunk[".class"] == name)
7676

7777

78-
def report_counter(counter: Counter, amount: int | None = None) -> None:
78+
def report_counter(counter: Counter[str], amount: int | None = None) -> None:
7979
for name, count in counter.most_common(amount):
8080
print(f" {count: <8} {name}")
8181
print()
@@ -89,7 +89,7 @@ def compress(chunk: JsonDict) -> JsonDict:
8989
cache: dict[int, JsonDict] = {}
9090
counter = 0
9191

92-
def helper(chunk: Any) -> Any:
92+
def helper(chunk: JsonDict) -> JsonDict:
9393
nonlocal counter
9494
if not isinstance(chunk, dict):
9595
return chunk
@@ -121,7 +121,7 @@ def helper(chunk: Any) -> Any:
121121
def decompress(chunk: JsonDict) -> JsonDict:
122122
cache: dict[int, JsonDict] = {}
123123

124-
def helper(chunk: Any) -> Any:
124+
def helper(chunk: JsonDict) -> JsonDict:
125125
if not isinstance(chunk, dict):
126126
return chunk
127127
if ".id" in chunk:
@@ -167,6 +167,7 @@ def main() -> None:
167167
if "build.*.json" in chunk.filename:
168168
build = chunk
169169
break
170+
assert build is not None
170171
original = json.dumps(build.data, sort_keys=True)
171172
print(f"Size of build.data.json, in kilobytes: {len(original) / 1024:.3f}")
172173

0 commit comments

Comments
 (0)