Skip to content

Commit 10c0981

Browse files
committed
Merge
2 parents cc3f5c2 + 4cfacc6 commit 10c0981

File tree

106 files changed

+5133
-945
lines changed

Some content is hidden

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

106 files changed

+5133
-945
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

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:

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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:

misc/async_matrix.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def plain_host_generator(func) -> Generator[str, None, None]:
7070
x = 0
7171
f = func()
7272
try:
73-
x = yield from f
73+
x = yield from f # noqa: F841
7474
finally:
7575
try:
7676
f.close()
@@ -80,7 +80,7 @@ def plain_host_generator(func) -> Generator[str, None, None]:
8080

8181
async def plain_host_coroutine(func) -> None:
8282
x = 0
83-
x = await func()
83+
x = await func() # noqa: F841
8484

8585

8686
@coroutine
@@ -89,7 +89,7 @@ def decorated_host_generator(func) -> Generator[str, None, None]:
8989
x = 0
9090
f = func()
9191
try:
92-
x = yield from f
92+
x = yield from f # noqa: F841
9393
finally:
9494
try:
9595
f.close()
@@ -100,7 +100,7 @@ def decorated_host_generator(func) -> Generator[str, None, None]:
100100
@coroutine
101101
async def decorated_host_coroutine(func) -> None:
102102
x = 0
103-
x = await func()
103+
x = await func() # noqa: F841
104104

105105

106106
# Main driver.

misc/build-debug-python.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash -eux
22

33
# Build a debug build of python, install it, and create a venv for it
4-
# This is mainly intended for use in our travis builds but it can work
4+
# This is mainly intended for use in our github actions builds but it can work
55
# locally. (Though it unfortunately uses brew on OS X to deal with openssl
66
# nonsense.)
77
# Usage: build-debug-python.sh <version> <install prefix> <venv location>

misc/cherry-pick-typeshed.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def main() -> None:
3737
sys.exit(f"error: Invalid commit {commit!r}")
3838

3939
if not os.path.exists("mypy") or not os.path.exists("mypyc"):
40-
sys.exit(f"error: This script must be run at the mypy repository root directory")
40+
sys.exit("error: This script must be run at the mypy repository root directory")
4141

4242
with tempfile.TemporaryDirectory() as d:
4343
diff_file = os.path.join(d, "diff")

scripts/find_type.py renamed to misc/find_type.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# " Convert to 0-based column offsets
1818
# let startcol = startcol - 1
1919
# " Change this line to point to the find_type.py script.
20-
# execute '!python3 /path/to/mypy/scripts/find_type.py % ' . startline . ' ' . startcol . ' ' . endline . ' ' . endcol . ' ' . mypycmd
20+
# execute '!python3 /path/to/mypy/misc/find_type.py % ' . startline . ' ' . startcol . ' ' . endline . ' ' . endcol . ' ' . mypycmd
2121
# endfunction
2222
# vnoremap <Leader>t :call RevealType()<CR>
2323
#

0 commit comments

Comments
 (0)