Skip to content

Improve cli help somewhat #19073

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

Draft
wants to merge 31 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
c95306e
failed attempt, very regex-heavy
wyattscarpenter May 9, 2025
5dbb010
ok I mean it works now but it doubles up insertions
wyattscarpenter May 9, 2025
c5c0857
works perfectly
wyattscarpenter May 9, 2025
82eb394
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 9, 2025
15236bd
get the strict flags another way, to make all the tests pass
wyattscarpenter May 9, 2025
4081906
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 9, 2025
b415f0f
generate the strict list in the build dir, so there won't be any funk…
wyattscarpenter May 9, 2025
00580de
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 9, 2025
98bc704
um, I meant srcdir. Sure.
wyattscarpenter May 9, 2025
a546416
bruh
wyattscarpenter May 9, 2025
c044f80
refactor out define_options
wyattscarpenter May 10, 2025
6a47e7d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 10, 2025
9ba2c9b
remove --experimental from dmypy's options after 'a short transition'…
wyattscarpenter May 10, 2025
8087150
move --use-fine-grained-cache to Incremental group
wyattscarpenter May 10, 2025
3a75ee6
create new 'experimental' group, rescuing --enable-incomplete-feature…
wyattscarpenter May 10, 2025
4f1e460
rename Optional arguments to Utility arguments, since all arguments a…
wyattscarpenter May 10, 2025
2a8a8e2
The metavar overrides the default of displaying the choices, so we ha…
wyattscarpenter May 10, 2025
8c61a64
update documentation
wyattscarpenter May 10, 2025
350fd38
update documentation so it's clear that an int field doesn't need to …
wyattscarpenter May 10, 2025
c0aa284
begin to enforce rules, although it's surprisingly failing
wyattscarpenter May 10, 2025
c76183d
continue automating, and correcting
wyattscarpenter May 10, 2025
72f1e5c
blacken
wyattscarpenter May 11, 2025
31dc2ff
remove the concern about links as it no longer seems to be useful
wyattscarpenter May 11, 2025
2c45a29
improve cli formatting error message and also linewrapping
wyattscarpenter May 11, 2025
67dd115
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 11, 2025
185371a
readd link I accidentally deleted
wyattscarpenter May 11, 2025
91233ca
name that occurs in python 3.9
wyattscarpenter May 11, 2025
52d2a4c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 11, 2025
26e221d
fix ci problems (type errors)
wyattscarpenter May 11, 2025
9706862
hold on a minute, this needs an s
wyattscarpenter May 11, 2025
01324aa
my arguments were in the wrong order
wyattscarpenter May 10, 2025
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
136 changes: 70 additions & 66 deletions docs/source/command_line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ for full details, see :ref:`running-mypy`.

This flag will add everything that matches ``.gitignore`` file(s) to :option:`--exclude`.

.. _optional-arguments:

Optional arguments
Utility arguments
******************

.. option:: -h, --help
Expand Down Expand Up @@ -764,7 +765,10 @@ of the above sections.
:option:`mypy --help` output.

Note: the exact list of flags enabled by running :option:`--strict` may change
over time.
over time. For this version of mypy, the list is:

.. include:: strict_list.rst


.. option:: --disable-error-code

Expand Down Expand Up @@ -1032,6 +1036,70 @@ in developing or debugging mypy internals.
cause mypy to type check the contents of ``temp.py`` instead of ``original.py``,
but error messages will still reference ``original.py``.

.. _enabling-incomplete-experimental-features:

Experimental features
*****************************************

.. option:: --enable-incomplete-feature {PreciseTupleTypes, InlineTypedDict}

Some features may require several mypy releases to implement, for example
due to their complexity, potential for backwards incompatibility, or
ambiguous semantics that would benefit from feedback from the community.
You can enable such features for early preview using this flag. Note that
it is not guaranteed that all features will be ultimately enabled by
default. In *rare cases* we may decide to not go ahead with certain
features.

List of currently incomplete/experimental features:

* ``PreciseTupleTypes``: this feature will infer more precise tuple types in
various scenarios. Before variadic types were added to the Python type system
by :pep:`646`, it was impossible to express a type like "a tuple with
at least two integers". The best type available was ``tuple[int, ...]``.
Therefore, mypy applied very lenient checking for variable-length tuples.
Now this type can be expressed as ``tuple[int, int, *tuple[int, ...]]``.
For such more precise types (when explicitly *defined* by a user) mypy,
for example, warns about unsafe index access, and generally handles them
in a type-safe manner. However, to avoid problems in existing code, mypy
does not *infer* these precise types when it technically can. Here are
notable examples where ``PreciseTupleTypes`` infers more precise types:

.. code-block:: python

numbers: tuple[int, ...]

more_numbers = (1, *numbers, 1)
reveal_type(more_numbers)
# Without PreciseTupleTypes: tuple[int, ...]
# With PreciseTupleTypes: tuple[int, *tuple[int, ...], int]

other_numbers = (1, 1) + numbers
reveal_type(other_numbers)
# Without PreciseTupleTypes: tuple[int, ...]
# With PreciseTupleTypes: tuple[int, int, *tuple[int, ...]]

if len(numbers) > 2:
reveal_type(numbers)
# Without PreciseTupleTypes: tuple[int, ...]
# With PreciseTupleTypes: tuple[int, int, int, *tuple[int, ...]]
else:
reveal_type(numbers)
# Without PreciseTupleTypes: tuple[int, ...]
# With PreciseTupleTypes: tuple[()] | tuple[int] | tuple[int, int]

* ``InlineTypedDict``: this feature enables non-standard syntax for inline
:ref:`TypedDicts <typeddict>`, for example:

.. code-block:: python

def test_values() -> {"foo": int, "bar": str}:
return {"foo": 42, "bar": "test"}

.. option:: --find-occurrences CLASS.MEMBER

This flag will make mypy print out all usages of a class member
based on static type information. This feature is experimental.

Report generation
*****************
Expand Down Expand Up @@ -1093,65 +1161,6 @@ format into the specified directory.
``mypy[reports]``.


Enabling incomplete/experimental features
*****************************************

.. option:: --enable-incomplete-feature {PreciseTupleTypes, InlineTypedDict}

Some features may require several mypy releases to implement, for example
due to their complexity, potential for backwards incompatibility, or
ambiguous semantics that would benefit from feedback from the community.
You can enable such features for early preview using this flag. Note that
it is not guaranteed that all features will be ultimately enabled by
default. In *rare cases* we may decide to not go ahead with certain
features.

List of currently incomplete/experimental features:

* ``PreciseTupleTypes``: this feature will infer more precise tuple types in
various scenarios. Before variadic types were added to the Python type system
by :pep:`646`, it was impossible to express a type like "a tuple with
at least two integers". The best type available was ``tuple[int, ...]``.
Therefore, mypy applied very lenient checking for variable-length tuples.
Now this type can be expressed as ``tuple[int, int, *tuple[int, ...]]``.
For such more precise types (when explicitly *defined* by a user) mypy,
for example, warns about unsafe index access, and generally handles them
in a type-safe manner. However, to avoid problems in existing code, mypy
does not *infer* these precise types when it technically can. Here are
notable examples where ``PreciseTupleTypes`` infers more precise types:

.. code-block:: python

numbers: tuple[int, ...]

more_numbers = (1, *numbers, 1)
reveal_type(more_numbers)
# Without PreciseTupleTypes: tuple[int, ...]
# With PreciseTupleTypes: tuple[int, *tuple[int, ...], int]

other_numbers = (1, 1) + numbers
reveal_type(other_numbers)
# Without PreciseTupleTypes: tuple[int, ...]
# With PreciseTupleTypes: tuple[int, int, *tuple[int, ...]]

if len(numbers) > 2:
reveal_type(numbers)
# Without PreciseTupleTypes: tuple[int, ...]
# With PreciseTupleTypes: tuple[int, int, int, *tuple[int, ...]]
else:
reveal_type(numbers)
# Without PreciseTupleTypes: tuple[int, ...]
# With PreciseTupleTypes: tuple[()] | tuple[int] | tuple[int, int]

* ``InlineTypedDict``: this feature enables non-standard syntax for inline
:ref:`TypedDicts <typeddict>`, for example:

.. code-block:: python

def test_values() -> {"int": int, "str": str}:
return {"int": 42, "str": "test"}


Miscellaneous
*************

Expand Down Expand Up @@ -1198,11 +1207,6 @@ Miscellaneous
type checking results. This can make it easier to integrate mypy
with continuous integration (CI) tools.

.. option:: --find-occurrences CLASS.MEMBER

This flag will make mypy print out all usages of a class member
based on static type information. This feature is experimental.

.. option:: --scripts-are-modules

This flag will give command line arguments that appear to be
Expand Down
20 changes: 20 additions & 0 deletions docs/source/html_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,35 @@
from sphinx.builders.html import StandaloneHTMLBuilder
from sphinx.environment import BuildEnvironment

from mypy.main import define_options


class MypyHTMLBuilder(StandaloneHTMLBuilder):
strict_file: Path

def __init__(self, app: Sphinx, env: BuildEnvironment) -> None:
super().__init__(app, env)
self._ref_to_doc = {}
self.strict_file = Path(self.srcdir) / "strict_list.rst"
self._add_strict_list()

def write_doc(self, docname: str, doctree: document) -> None:
super().write_doc(docname, doctree)
self._ref_to_doc.update({_id: docname for _id in doctree.ids})

def _add_strict_list(self) -> None:
strict_flags: list[str]
_, strict_flags, _ = define_options()
strict_part = ", ".join(f":option:`{s} <mypy {s}>`" for s in strict_flags)
if (
not strict_part
or strict_part.isspace()
or len(strict_part) < 20
or len(strict_part) > 2000
):
raise ValueError(f"{strict_part=}, which doesn't look right (by a simple heuristic).")
self.strict_file.write_text(strict_part)

def _verify_error_codes(self) -> None:
from mypy.errorcodes import error_codes

Expand Down Expand Up @@ -55,6 +74,7 @@ def _write_ref_redirector(self) -> None:
def finish(self) -> None:
super().finish()
self._write_ref_redirector()
self.strict_file.unlink()


def setup(app: Sphinx) -> dict[str, Any]:
Expand Down
Loading