Skip to content

Added CLI support for Mypy Plugins - #18104

Open
dibrinsofor wants to merge 8 commits into
python:masterfrom
dibrinsofor:plugins-from-cli
Open

dibrinsofor wants to merge 8 commits into
python:masterfrom
dibrinsofor:plugins-from-cli

Conversation

@dibrinsofor

Copy link
Copy Markdown

Fixes #11667

(Explain how this PR changes mypy.)
Includes a command line argument (--plugins), as a supplementary approach to supplying Mypy plugins.

Not sure how to add tests for this, but have tested locally and extended the docs to highlight this change.

Comment thread mypy/main.py Outdated
internals_group.add_argument("--pdb", action="store_true", help="Invoke pdb on fatal error")
internals_group.add_argument(
"--plugins",
nargs="*",

@brianschubert brianschubert Nov 4, 2024 •

Copy link
Copy Markdown
Collaborator

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?

Comment thread mypy/main.py
@github-actions

This comment has been minimized.

Comment thread docs/source/command_line.rst Outdated
This flag will invoke the Python debugger when mypy encounters
a fatal error.

.. option:: --plugins {MODULE|PLUGIN_FILE} ...

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

@dibrinsofor dibrinsofor Nov 4, 2024 •

Copy link
Copy Markdown
Author

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?

@github-actions

This comment has been minimized.

1 similar comment
@github-actions

This comment has been minimized.

dibrinsofor and others added 8 commits October 1, 2026 01:07
Signed-off-by: Dibri Nsofor <dibrinsofor@gmail.com>
Signed-off-by: Dibri Nsofor <dibrinsofor@gmail.com>
Signed-off-by: Dibri Nsofor <dibrinsofor@gmail.com>
Signed-off-by: Dibri Nsofor <dibrinsofor@gmail.com>
Signed-off-by: Dibri Nsofor <dibrinsofor@gmail.com>
Signed-off-by: Dibri Nsofor <dibrinsofor@gmail.com>
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add --plugins command-line option

2 participants