Skip to content
5 changes: 5 additions & 0 deletions docs/source/command_line.rst
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,11 @@ in developing or debugging mypy internals.
This flag will invoke the Python debugger when mypy encounters
a fatal error.

.. option:: --plugins {MODULE|PLUGIN_FILE} ...
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider matching this with argument's metavar so that the output of mypy --help looks the same.

Also, plugins is listed before pdb in the config file documentation, so it may be worth using the same order here for symmetry.

Copy link
Author

Choose a reason for hiding this comment

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

The ordering seems to be consistent already

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, maybe I'm looking at a different page. The page I'm looking at is this one: https://mypy.readthedocs.io/en/stable/config_file.html#confval-plugins, which has plugins before pdb

Copy link
Author

@dibrinsofor dibrinsofor Nov 4, 2024

Choose a reason for hiding this comment

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

@brianschubert you're right, shouldn't the ordering from command_line.rst be preserved?


This flag acts as a supplementary way to pass (a list of) plugins to customize
Mypy's type checking approach. See :ref:`extending-mypy` for more details.

.. option:: --show-traceback, --tb

If set, this flag will display a full traceback when mypy
Expand Down
10 changes: 10 additions & 0 deletions mypy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,12 @@ def add_invertible_flag(
title="Advanced options", description="Debug and customize mypy internals."
)
internals_group.add_argument("--pdb", action="store_true", help="Invoke pdb on fatal error")
internals_group.add_argument(
"--plugins",
nargs="*",
Copy link
Collaborator

@brianschubert brianschubert Nov 4, 2024

Choose a reason for hiding this comment

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

Using nargs="*" might be problematic, since this swallows all of the following positional arguments. For example, the invocation

mypy --plugins my_plugin src/foo.py

will interpret both my_plugin and src/foo.py as arguments to plugins, and will error due to no targets being given.

Maybe a repeatable argument or a string argument with the same syntax as the config file would work better?

dest="special-opts:cli_plugins",
help="Include user defined plugins during Mypy's type analysis",
)
internals_group.add_argument(
"--show-traceback", "--tb", action="store_true", help="Show traceback on fatal error"
)
Expand Down Expand Up @@ -1291,6 +1297,10 @@ def set_strict_flags() -> None:
special_opts = argparse.Namespace()
parser.parse_args(args, SplitNamespace(options, special_opts, "special-opts:"))

# Parse extra plugins passed via cli args
if special_opts.cli_plugins:
options.plugins.extend(special_opts.cli_plugins)

# The python_version is either the default, which can be overridden via a config file,
# or stored in special_opts and is passed via the command line.
options.python_version = special_opts.python_version or options.python_version
Expand Down