Skip to content

Improve daemon docs; add docs for dmypy suggest #8032

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 29, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Improve daemon docs; add docs for dmypy suggest
  • Loading branch information
Ivan Levkivskyi committed Nov 28, 2019
commit 4b59afc44888459e1e59ed623a000e945c5a171a
118 changes: 116 additions & 2 deletions docs/source/mypy_daemon.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ changed a few files. You can use :ref:`remote caching <remote-cache>`
to speed up the initial run. The speedup can be significant if
you have a large codebase.

Additional features
*******************
Daemon client commands
**********************

While ``dmypy run`` is sufficient for most uses, some workflows
(ones using :ref:`remote caching <remote-cache>`, perhaps),
Expand Down Expand Up @@ -94,6 +94,118 @@ Use ``dmypy --help`` for help on additional commands and command-line
options not discussed here, and ``dmypy <command> --help`` for help on
command-specific options.

Additional daemon flags
***********************

.. option:: --status-file FILE

Status file to retrieve daemon details. This is normally a JSON file
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested edit: "Use FILE as the status file for storing daemon runtime state. ..."

that contains information about daemon process and connection. Default is
``.dmypy.json``.

.. option:: --log-file FILE

Direct daemon stdout/stderr to ``FILE``. This is useful for debugging daemon
crashes, since the server traceback may be not printed to client stderr. Only
available for ``start``, ``restart``, and ``run`` commands.

.. option:: --timeout TIMEOUT

Server shutdown timeout (in seconds). Only available for ``start``,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested edit: Automatically shut down server after TIMEOUT seconds of inactivity.

``restart``, and ``run`` commands.

.. option:: --fswatcher-dump-file FILE

Collect information about the current file state. Only available for
``status`` command.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this description is not detailed enough to be useful. I think that it's fine to leave this undocumented for now. Altarnatively, at least the purpose of this information and the structure/contents of it should probably be documented.


.. option:: --perf-stats-file FILE

Write performance telemetry information to the given file. Only available
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Tthis is not telemetry, since it's only written to a local file.

Suggested edit: "Write performance profiling information to FILE.

for ``check``, ``recheck``, and ``run`` commands.

.. option:: --update FILE

Files in the run to add or check again, may be repeated. Default: all
files from the previous run. Only available for ``recheck`` command.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Give some motivation for why somebody might want to use this option. Something about speeding up runs if there are thousands of files, and maybe suggest using file events to find the modified files.

Maybe also mention that this option is never required and is only available for speeding things up.


.. option:: --remove FILE

Files to remove from the run, may be repeated. Only available for
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This suggests that this is needed whenever files are removed, which is not the case? Similar to above, document that this can be used as an optimization to avoid looking at all source files for deletions.

``recheck`` command.

Static inference of annotations
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move this to a separate rst file, since this is quite distinct from other features provided by dmypy, and mostly relevant for users that are going to write integrations (since the low-level UX is kind of hard to use).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can keep it in the same file for now. It is anyway at the very end and it is probably OK to attract some attention to it.

Also I can't find a good name for a section that would look good in table of contents with the daemon. I think we can move it to a separate file when we will add dmypy reveal, then it will look more natural.

*******************************

Mypy daemon supports (as experimental feature) statically inferring draft type
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grammar nits: "as an experimental feature"; "inferring a draft type"

It's probably worth mentioning that this is a low-level feature that is usually driven by other tools such as editor integrations. Maybe add link to the PyCharm plugin as an example.

annotation for a given function or method. For example, given this program:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incomplete sentence "For example, ..." (no verb). Suggested edit: "In this example, the function format_id has no annotation:"


.. code-block:: python

def format_id(user):
return "User: {}".format(user)

root = format_id(0)

Mypy can infer that ``format_id()`` takes an ``int`` and returns a ``str``.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe explain the algorithm in little detail, such as mentioning that mypy looks at call sites and the function definition to infer types.

To get a suggested signature for a function, use ``dmypy suggest FUNCTION``,
where the function may be specified in either of two forms:

* By its fully qualified name, i.e. ``[package.]module.[class.]function``

* By its textual location, i.e. ``/path/to/file.py:line``
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does a relevative path also work? I assume that the line can refer to any line within a function; maybe mention this as well.


Running this command will produce a suggested signature in the format
``(param_type_1, param_type_2, ...) -> ret_type``. This may be used by IDEs
or similar tools to propose to user and/or insert the annotation into file.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned earlier, this information is key and should probably be presented earlier.

Maybe discuss what happens to arguments with default values, *args and **kwargs.


This command can also be used to find an improvement for an existing (imprecise)
annotation. The following flags customize various aspects of the ``dmypy suggest``
command.

.. option:: --json

Use JSON format to output the signature, so that `PyAnnotate`_ can use it
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested edit: "Output the signature as JSON, so that ..."

Maybe also give an example of the JSON?

to apply a suggestion to file.

.. option:: --no-errors

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

.. option:: --no-any

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

.. option:: --flex-any PERCENTAGE

Allow ``Any`` types in suggested signature if they go above a certain score.
Scores are from ``0`` (same as ``--no-any``) to ``1``.

.. option:: --try-text

Try using ``unicode`` wherever ``str`` is inferred. This flag may be useful
for annotating Python 2/3 straddling code.

.. option:: --callsites

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

.. option:: --use-fixme NAME

A dummy name to use instead of plain ``Any`` for types that cannot
be inferred.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add some motivation for this feature.


.. option:: --max-guesses NUMBER

Set the maximum number of types to try for a function (default ``64``).

.. TODO: Add similar sections about go to definition, find usages, and
reveal type when added.

Limitations
***********

Expand All @@ -102,3 +214,5 @@ Limitations
limitation. This can be defined
through the command line or through a
:ref:`configuration file <config-file>`.

.. _PyAnnotate: https://github.com/dropbox/pyannotate
4 changes: 2 additions & 2 deletions mypy/dmypy/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ def __init__(self, prog: str) -> None:
help="Regular mypy flags and files (precede with --)")

recheck_parser = p = subparsers.add_parser('recheck', formatter_class=AugmentedHelpFormatter,
help="Re-check the previous list of files, with optional modifications (requires daemon).")
help="Re-check the previous list of files, with optional modifications (requires daemon)")
p.add_argument('-v', '--verbose', action='store_true', help="Print detailed status")
p.add_argument('-q', '--quiet', action='store_true', help=argparse.SUPPRESS) # Deprecated
p.add_argument('--junit-xml', help="Write junit.xml to the given file")
p.add_argument('--perf-stats-file', help='write telemetry information to the given file')
p.add_argument('--update', metavar='FILE', nargs='*',
help="Files in the run to add or check again (default: all from previous run)..")
help="Files in the run to add or check again (default: all from previous run)")
p.add_argument('--remove', metavar='FILE', nargs='*',
help="Files to remove from the run")

Expand Down
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