Skip to content

Commit 298bc27

Browse files
committed
Merge branch 'master' into mypyc-lower-get-item
2 parents 09140b8 + ec4ccb0 commit 298bc27

File tree

348 files changed

+8219
-1919
lines changed

Some content is hidden

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

348 files changed

+8219
-1919
lines changed

.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/)|misc/typeshed_patches' # Exclude all vendored code from lints
22
repos:
33
- repo: https://github.com/pre-commit/pre-commit-hooks
4-
rev: v4.5.0 # must match test-requirements.txt
4+
rev: v4.5.0
55
hooks:
66
- id: trailing-whitespace
77
- id: end-of-file-fixer
88
- repo: https://github.com/psf/black-pre-commit-mirror
9-
rev: 24.8.0 # must match test-requirements.txt
9+
rev: 24.8.0
1010
hooks:
1111
- id: black
1212
exclude: '^(test-data/)'
1313
- repo: https://github.com/astral-sh/ruff-pre-commit
14-
rev: v0.6.9 # must match test-requirements.txt
14+
rev: v0.6.9
1515
hooks:
1616
- id: ruff
1717
args: [--exit-non-zero-on-fix]

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ recursive-include mypy/typeshed *.pyi
99

1010
# mypy and mypyc
1111
include mypy/py.typed
12+
include mypyc/py.typed
1213
recursive-include mypy *.py
1314
recursive-include mypyc *.py
1415

README.md

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Got a question?
1717

1818
We are always happy to answer questions! Here are some good places to ask them:
1919

20-
- for anything you're curious about, try [gitter chat](https://gitter.im/python/typing)
2120
- for general questions about Python typing, try [typing discussions](https://github.com/python/typing/discussions)
21+
- for anything you're curious about, try [gitter chat](https://gitter.im/python/typing)
2222

2323
If you're just getting started,
2424
[the documentation](https://mypy.readthedocs.io/en/stable/index.html)
@@ -30,7 +30,6 @@ If you think you've found a bug:
3030
- check our [common issues page](https://mypy.readthedocs.io/en/stable/common_issues.html)
3131
- search our [issue tracker](https://github.com/python/mypy/issues) to see if
3232
it's already been reported
33-
- consider asking on [gitter chat](https://gitter.im/python/typing)
3433

3534
To report a bug or request an enhancement:
3635

@@ -101,8 +100,6 @@ repo directly:
101100

102101
```bash
103102
python3 -m pip install -U git+https://github.com/python/mypy.git
104-
# or if you don't have 'git' installed
105-
python3 -m pip install -U https://github.com/python/mypy/zipball/master
106103
```
107104

108105
Now you can type-check the [statically typed parts] of a program like this:
@@ -118,14 +115,16 @@ programs, even if mypy reports type errors:
118115
python3 PROGRAM
119116
```
120117

121-
You can also try mypy in an [online playground](https://mypy-play.net/) (developed by
122-
Yusuke Miyazaki). If you are working with large code bases, you can run mypy in
118+
If you are working with large code bases, you can run mypy in
123119
[daemon mode], that will give much faster (often sub-second) incremental updates:
124120

125121
```bash
126122
dmypy run -- PROGRAM
127123
```
128124

125+
You can also try mypy in an [online playground](https://mypy-play.net/) (developed by
126+
Yusuke Miyazaki).
127+
129128
[statically typed parts]: https://mypy.readthedocs.io/en/latest/getting_started.html#function-signatures-and-dynamic-vs-static-typing
130129
[daemon mode]: https://mypy.readthedocs.io/en/stable/mypy_daemon.html
131130

@@ -134,18 +133,17 @@ Integrations
134133

135134
Mypy can be integrated into popular IDEs:
136135

136+
- VS Code: provides [basic integration](https://code.visualstudio.com/docs/python/linting#_mypy) with mypy.
137137
- Vim:
138138
- Using [Syntastic](https://github.com/vim-syntastic/syntastic): in `~/.vimrc` add
139139
`let g:syntastic_python_checkers=['mypy']`
140140
- Using [ALE](https://github.com/dense-analysis/ale): should be enabled by default when `mypy` is installed,
141141
or can be explicitly enabled by adding `let b:ale_linters = ['mypy']` in `~/vim/ftplugin/python.vim`
142142
- Emacs: using [Flycheck](https://github.com/flycheck/)
143143
- Sublime Text: [SublimeLinter-contrib-mypy](https://github.com/fredcallaway/SublimeLinter-contrib-mypy)
144-
- Atom: [linter-mypy](https://atom.io/packages/linter-mypy)
145-
- PyCharm: [mypy plugin](https://github.com/dropbox/mypy-PyCharm-plugin) (PyCharm integrates
146-
[its own implementation](https://www.jetbrains.com/help/pycharm/type-hinting-in-product.html) of [PEP 484](https://peps.python.org/pep-0484/))
147-
- VS Code: provides [basic integration](https://code.visualstudio.com/docs/python/linting#_mypy) with mypy.
148-
- pre-commit: use [pre-commit mirrors-mypy](https://github.com/pre-commit/mirrors-mypy).
144+
- PyCharm: [mypy plugin](https://github.com/dropbox/mypy-PyCharm-plugin)
145+
- pre-commit: use [pre-commit mirrors-mypy](https://github.com/pre-commit/mirrors-mypy), although
146+
note by default this will limit mypy's ability to analyse your third party dependencies.
149147

150148
Web site and documentation
151149
--------------------------
@@ -171,8 +169,6 @@ contributors of all experience levels.
171169

172170
To get started with developing mypy, see [CONTRIBUTING.md](CONTRIBUTING.md).
173171

174-
If you need help getting started, don't hesitate to ask on [gitter](https://gitter.im/python/typing).
175-
176172
Mypyc and compiled version of mypy
177173
----------------------------------
178174

@@ -190,4 +186,4 @@ To use a compiled version of a development
190186
version of mypy, directly install a binary from
191187
<https://github.com/mypyc/mypy_mypyc-wheels/releases/latest>.
192188

193-
To contribute to the mypyc project, check out <https://github.com/mypyc/mypyc>
189+
To contribute to the mypyc project, check out the issue tracker at <https://github.com/mypyc/mypyc>

docs/requirements-docs.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
sphinx>=8.1.0
22
furo>=2022.3.4
33
myst-parser>=4.0.0
4+
sphinx_inline_tabs>=2023.04.21

docs/source/command_line.rst

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,17 @@ imports.
166166
167167
For more details, see :ref:`ignore-missing-imports`.
168168

169+
.. option:: --follow-untyped-imports
170+
171+
This flag makes mypy analyze imports from installed packages even if
172+
missing a :ref:`py.typed marker or stubs <installed-packages>`.
173+
174+
.. warning::
175+
176+
Note that analyzing all unannotated modules might result in issues
177+
when analyzing code not designed to be type checked and may significantly
178+
increase how long mypy takes to run.
179+
169180
.. option:: --follow-imports {normal,silent,skip,error}
170181

171182
This flag adjusts how mypy follows imported modules that were not
@@ -537,12 +548,12 @@ potentially problematic or redundant in some way.
537548

538549
This limitation will be removed in future releases of mypy.
539550

540-
.. option:: --report-deprecated-as-error
551+
.. option:: --report-deprecated-as-note
541552

542-
By default, mypy emits notes if your code imports or uses deprecated
543-
features. This flag converts such notes to errors, causing mypy to
544-
eventually finish with a non-zero exit code. Features are considered
545-
deprecated when decorated with ``warnings.deprecated``.
553+
If error code ``deprecated`` is enabled, mypy emits errors if your code
554+
imports or uses deprecated features. This flag converts such errors to
555+
notes, causing mypy to eventually finish with a zero exit code. Features
556+
are considered deprecated when decorated with ``warnings.deprecated``.
546557

547558
.. _miscellaneous-strictness-flags:
548559

docs/source/conf.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@
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", "docs.source.html_builder", "myst_parser"]
38+
extensions = [
39+
"sphinx.ext.intersphinx",
40+
"sphinx_inline_tabs",
41+
"docs.source.html_builder",
42+
"myst_parser",
43+
]
3944

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

docs/source/config_file.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,24 @@ section of the command line docs.
315315
match the name of the *imported* module, not the module containing the
316316
import statement.
317317

318+
.. confval:: follow_untyped_imports
319+
320+
:type: boolean
321+
:default: False
322+
323+
Makes mypy analyze imports from installed packages even if missing a
324+
:ref:`py.typed marker or stubs <installed-packages>`.
325+
326+
If this option is used in a per-module section, the module name should
327+
match the name of the *imported* module, not the module containing the
328+
import statement.
329+
330+
.. warning::
331+
332+
Note that analyzing all unannotated modules might result in issues
333+
when analyzing code not designed to be type checked and may significantly
334+
increase how long mypy takes to run.
335+
318336
.. confval:: follow_imports
319337

320338
:type: string

docs/source/error_code_list2.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,13 @@ incorrect control flow or conditional checks that are accidentally always true o
236236
Check that imported or used feature is deprecated [deprecated]
237237
--------------------------------------------------------------
238238

239-
By default, mypy generates a note if your code imports a deprecated feature explicitly with a
239+
If you use :option:`--enable-error-code deprecated <mypy --enable-error-code>`,
240+
mypy generates an error if your code imports a deprecated feature explicitly with a
240241
``from mod import depr`` statement or uses a deprecated feature imported otherwise or defined
241242
locally. Features are considered deprecated when decorated with ``warnings.deprecated``, as
242-
specified in `PEP 702 <https://peps.python.org/pep-0702>`_. You can silence single notes via
243-
``# type: ignore[deprecated]`` or turn off this check completely via ``--disable-error-code=deprecated``.
244-
Use the :option:`--report-deprecated-as-error <mypy --report-deprecated-as-error>` option for
245-
more strictness, which turns all such notes into errors.
243+
specified in `PEP 702 <https://peps.python.org/pep-0702>`_.
244+
Use the :option:`--report-deprecated-as-note <mypy --report-deprecated-as-note>` option to
245+
turn all such errors into notes.
246246

247247
.. note::
248248

docs/source/extending_mypy.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,4 +245,4 @@ Mypy ships ``mypy.plugins.proper_plugin`` plugin which can be useful
245245
for plugin authors, since it finds missing ``get_proper_type()`` calls,
246246
which is a pretty common mistake.
247247

248-
It is recommended to enable it is a part of your plugin's CI.
248+
It is recommended to enable it as a part of your plugin's CI.

docs/source/running_mypy.rst

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,31 @@ If you are getting this error, try to obtain type hints for the library you're u
277277
to the library -- see our documentation on creating
278278
:ref:`PEP 561 compliant packages <installed-packages>`.
279279

280+
4. Force mypy to analyze the library as best as it can (as if the library provided
281+
a ``py.typed`` file), despite it likely missing any type annotations. In general,
282+
the quality of type checking will be poor and mypy may have issues when
283+
analyzing code not designed to be type checked.
284+
285+
You can do this via setting the
286+
:option:`--follow-untyped-imports <mypy --follow-untyped-imports>`
287+
command line flag or :confval:`follow_untyped_imports` config file option to True.
288+
This option can be specified on a per-module basis as well:
289+
290+
.. tab:: mypy.ini
291+
292+
.. code-block:: ini
293+
294+
[mypy-untyped_package.*]
295+
follow_untyped_imports = True
296+
297+
.. tab:: pyproject.toml
298+
299+
.. code-block:: toml
300+
301+
[[tool.mypy.overrides]]
302+
module = ["untyped_package.*"]
303+
follow_untyped_imports = true
304+
280305
If you are unable to find any existing type hints nor have time to write your
281306
own, you can instead *suppress* the errors.
282307

@@ -293,10 +318,22 @@ not catch errors in its use.
293318
suppose your codebase
294319
makes heavy use of an (untyped) library named ``foobar``. You can silence
295320
all import errors associated with that library and that library alone by
296-
adding the following section to your config file::
321+
adding the following section to your config file:
322+
323+
.. tab:: mypy.ini
297324

298-
[mypy-foobar.*]
299-
ignore_missing_imports = True
325+
.. code-block:: ini
326+
327+
[mypy-foobar.*]
328+
ignore_missing_imports = True
329+
330+
.. tab:: pyproject.toml
331+
332+
.. code-block:: toml
333+
334+
[[tool.mypy.overrides]]
335+
module = ["foobar.*"]
336+
ignore_missing_imports = true
300337
301338
Note: this option is equivalent to adding a ``# type: ignore`` to every
302339
import of ``foobar`` in your codebase. For more information, see the
@@ -309,11 +346,21 @@ not catch errors in its use.
309346
in your codebase, use :option:`--disable-error-code=import-untyped <mypy --ignore-missing-imports>`.
310347
See :ref:`code-import-untyped` for more details on this error code.
311348

312-
You can also set :confval:`disable_error_code`, like so::
349+
You can also set :confval:`disable_error_code`, like so:
350+
351+
.. tab:: mypy.ini
352+
353+
.. code-block:: ini
354+
355+
[mypy]
356+
disable_error_code = import-untyped
357+
358+
.. tab:: pyproject.toml
313359

314-
[mypy]
315-
disable_error_code = import-untyped
360+
.. code-block:: ini
316361
362+
[tool.mypy]
363+
disable_error_code = ["import-untyped"]
317364
318365
You can also set the :option:`--ignore-missing-imports <mypy --ignore-missing-imports>`
319366
command line flag or set the :confval:`ignore_missing_imports` config file

0 commit comments

Comments
 (0)