Skip to content

Commit 54973fb

Browse files
authored
Various small tweaks to mypy daemon documentation (python#8041)
Document the `recheck` command and update wording in many places. Reorder a few things.
1 parent 7fa4425 commit 54973fb

File tree

1 file changed

+70
-53
lines changed

1 file changed

+70
-53
lines changed

docs/source/mypy_daemon.rst

Lines changed: 70 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ require more precise control over the lifetime of the daemon process:
8787
* ``dmypy check <files>`` checks a set of files using an already
8888
running daemon.
8989

90+
* ``dmypy recheck`` checks the same set of files as the most recent
91+
``check`` or ``recheck`` command. (You can also use the :option:`--update`
92+
and :option:`--remove` options to alter the set of files, and to define
93+
which files should be processed.)
94+
9095
* ``dmypy status`` checks whether a daemon is running. It prints a
9196
diagnostic and exits with ``0`` if there is a running daemon.
9297

@@ -101,60 +106,69 @@ Additional daemon flags
101106

102107
Use ``FILE`` as the status file for storing daemon runtime state. This is
103108
normally a JSON file that contains information about daemon process and
104-
connection. Default is ``.dmypy.json`` in current directory.
109+
connection. The default path is ``.dmypy.json`` in the current working
110+
directory.
105111

106112
.. option:: --log-file FILE
107113

108114
Direct daemon stdout/stderr to ``FILE``. This is useful for debugging daemon
109-
crashes, since the server traceback may be not printed to client stderr.
110-
Only available for ``start``, ``restart``, and ``run`` commands.
115+
crashes, since the server traceback is not always printed by the client.
116+
This is available for the ``start``, ``restart``, and ``run`` commands.
111117

112118
.. option:: --timeout TIMEOUT
113119

114120
Automatically shut down server after ``TIMEOUT`` seconds of inactivity.
115-
Only available for ``start``, ``restart``, and ``run`` commands.
121+
This is available for the ``start``, ``restart``, and ``run`` commands.
116122

117-
.. option:: --fswatcher-dump-file FILE
123+
.. option:: --update FILE
118124

119-
Collect information about the current file state. Only available for
120-
``status`` command. This will dump a JSON to ``FILE`` in the format
121-
``{path: [modification_time, size, content_hash]}``. This is useful for
122-
debugging the built-in file system watcher. *Note:* this is an internal
123-
flag and the format may change.
125+
Re-check ``FILE``, or add it to the set of files being
126+
checked (and check it). This option may be repeated, and it's only available for
127+
the ``recheck`` command. By default, mypy finds and checks all files changed
128+
since the previous run and files that depend on them. However, if you use this option
129+
(and/or :option:`--remove`), mypy assumes that only the explicitly
130+
specified files have changed. This is only useful to
131+
speed up mypy if you type check a very large number of files, and use an
132+
external, fast file system watcher, such as `watchman`_ or
133+
`watchdog`_, to determine which files got edited or deleted.
134+
*Note:* This option is never required and is only available for
135+
performance tuning.
124136

125-
.. option:: --perf-stats-file FILE
137+
.. option:: --remove FILE
126138

127-
Write performance profiling information to ``FILE``. Only available
128-
for ``check``, ``recheck``, and ``run`` commands.
139+
Remove ``FILE`` from the set of files being checked. This option may be
140+
repeated. This is only available for the
141+
``recheck`` command. See :option:`--update` above for when this may be useful.
142+
*Note:* This option is never required and is only available for performance
143+
tuning.
129144

130-
.. option:: --update FILE
145+
.. option:: --fswatcher-dump-file FILE
131146

132-
Files in the run to add or check again, may be repeated. Default: all
133-
files from the previous run. Only available for ``recheck`` command.
134-
This is useful when type checking thousands of files and using external
135-
fast file system watcher, like `watchman`_ or `watchdog`_, to speed
136-
things up. *Note:* this option is never required and is only available
137-
for performance tuning.
147+
Collect information about the current internal file state. This is
148+
only available for the ``status`` command. This will dump JSON to
149+
``FILE`` in the format ``{path: [modification_time, size,
150+
content_hash]}``. This is useful for debugging the built-in file
151+
system watcher. *Note:* This is an internal flag and the format may
152+
change.
138153

139-
.. option:: --remove FILE
154+
.. option:: --perf-stats-file FILE
140155

141-
Files to remove from the run, may be repeated. Only available for
142-
``recheck`` command. This flag an be used as an optimization to avoid
143-
looking at all source files for deletions. *Note:* this option is never
144-
required and is only available for performance tuning.
156+
Write performance profiling information to ``FILE``. This is only available
157+
for the ``check``, ``recheck``, and ``run`` commands.
145158

146159
Static inference of annotations
147160
*******************************
148161

149-
Mypy daemon supports (as an experimental feature) statically inferring
150-
a draft type annotation for a given function or method. Running
151-
``dmypy suggest FUNCTION`` will produce a suggested signature in the format
152-
``(param_type_1, param_type_2, ...) -> ret_type`` (including named and
153-
star arguments).
162+
The mypy daemon supports (as an experimental feature) statically inferring
163+
draft function and method type annotations. Use ``dmypy suggest FUNCTION`` to
164+
generate a draft signature in the format
165+
``(param_type_1, param_type_2, ...) -> ret_type`` (types are included for all
166+
arguments, including keyword-only arguments, ``*args`` and ``**kwargs``).
154167

155-
This low level command may be used by editors, IDEs, or similar tools, like
156-
`mypy plugin for PyCharm`_, to propose an annotation to user and/or to insert
157-
the annotation into a source file.
168+
This is a low-level feature intended to be used by editor integrations,
169+
IDEs, and other tools (for example, the `mypy plugin for PyCharm`_),
170+
to automatically add annotations to source files, or to propose function
171+
signatures.
158172

159173
In this example, the function ``format_id()`` has no annotation:
160174

@@ -165,26 +179,29 @@ In this example, the function ``format_id()`` has no annotation:
165179
166180
root = format_id(0)
167181
168-
Mypy can use call sites and return statements (plus extra heuristics such as
169-
a signature in superclass for methods) to infer that ``format_id()`` takes
170-
an ``int`` and returns a ``str``. To get a suggested signature for a function,
171-
use ``dmypy suggest FUNCTION``, where the function may be specified in
172-
either of two forms:
182+
``dymypy suggest`` uses call sites, return statements, and other heuristics (such as
183+
looking for signatures in base classes) to infer that ``format_id()`` accepts
184+
an ``int`` argument and returns a ``str``. Use ``dmypy suggest module.format_id`` to
185+
print the suggested signature for the function.
173186

174-
* By its fully qualified name, i.e. ``[package.]module.[class.]function``
187+
More generally, the target function may be specified in two ways:
175188

176-
* By its textual location, i.e. ``/path/to/file.py:line``. The path can be
189+
* By its fully qualified name, i.e. ``[package.]module.[class.]function``.
190+
191+
* By its location in a source file, i.e. ``/path/to/file.py:line``. The path can be
177192
absolute or relative, and ``line`` can refer to any line number within
178193
the function body.
179194

180-
This command can also be used to find an improvement for an existing (imprecise)
181-
annotation. The following flags customize various aspects of the ``dmypy suggest``
195+
This command can also be used to find a more precise alternative for an existing,
196+
imprecise annotation with some ``Any`` types.
197+
198+
The following flags customize various aspects of the ``dmypy suggest``
182199
command.
183200

184201
.. option:: --json
185202

186-
Output the signature as JSON, so that `PyAnnotate`_ can use it to apply
187-
a suggestion to file. An example JSON looks like this:
203+
Output the signature as JSON, so that `PyAnnotate`_ can read it and add
204+
the signature to the source file. Here is what the JSON looks like:
188205

189206
.. code-block:: python
190207
@@ -196,39 +213,39 @@ command.
196213
197214
.. option:: --no-errors
198215

199-
Only produce suggestions that cause no errors in the checked code. By default
216+
Only produce suggestions that cause no errors in the checked code. By default,
200217
mypy will try to find the most precise type, even if it causes some type errors.
201218

202219
.. option:: --no-any
203220

204221
Only produce suggestions that don't contain ``Any`` types. By default mypy
205222
proposes the most precise signature found, even if it contains ``Any`` types.
206223

207-
.. option:: --flex-any PERCENTAGE
224+
.. option:: --flex-any FRACTION
208225

209-
Allow ``Any`` types in suggested signature if they go above a certain score.
210-
Scores are from ``0`` (same as ``--no-any``) to ``1``.
226+
Only allow some fraction of types in the suggested signature to be ``Any`` types.
227+
The fraction ranges from ``0`` (same as ``--no-any``) to ``1``.
211228

212229
.. option:: --try-text
213230

214-
Try using ``unicode`` wherever ``str`` is inferred. This flag may be useful
231+
Try also using ``unicode`` wherever ``str`` is inferred. This flag may be useful
215232
for annotating Python 2/3 straddling code.
216233

217234
.. option:: --callsites
218235

219236
Only find call sites for a given function instead of suggesting a type.
220-
This will produce a list including textual locations and types of actual
237+
This will produce a list with line numbers and types of actual
221238
arguments for each call: ``/path/to/file.py:line: (arg_type_1, arg_type_2, ...)``.
222239

223240
.. option:: --use-fixme NAME
224241

225-
A dummy name to use instead of plain ``Any`` for types that cannot
242+
Use a dummy name instead of plain ``Any`` for types that cannot
226243
be inferred. This may be useful to emphasize to a user that a given type
227-
can't be inferred and needs to be entered manually.
244+
couldn't be inferred and needs to be entered manually.
228245

229246
.. option:: --max-guesses NUMBER
230247

231-
Set the maximum number of types to try for a function (default ``64``).
248+
Set the maximum number of types to try for a function (default: ``64``).
232249

233250
.. TODO: Add similar sections about go to definition, find usages, and
234251
reveal type when added, and then move this to a separate file.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy