Skip to content

mypy crashes with python 3.14 within argparse #19150

Closed
@kasium

Description

@kasium

Crash Report

When using python 3.14, mypy crashes right away. This is due the AugmentedHelpFormatter class in mypy which does not accept all arguments of argparse.HelpFormatter. In python 3.14,_get_formatter of argparse will pass prefix_chars which is not supported by AugmentedHelpFormatter.

Proposal: change the constructor of AugmentedHelpFormatter like

class AugmentedHelpFormatter(argparse.RawDescriptionHelpFormatter):
    def __init__(self, prog: str, **kwargs: Any) -> None:
        super().__init__(prog=prog, max_help_position=28, **kwargs)

By the way, the same applies to the color keyword, which is passed as well

Traceback

  File "venv314/lib/python3.14/site-packages/mypy/__main__.py", line 15, in console_entry
    main()
    ~~~~^^
  File "venv314/lib/python3.14/site-packages/mypy/main.py", line 88, in main
    sources, options = process_options(args, stdout=stdout, stderr=stderr, fscache=fscache)
                       ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "venv314/lib/python3.14/site-packages/mypy/main.py", line 1055, in process_options
    parser.add_argument(
    ~~~~~~~~~~~~~~~~~~~^
        "--enable-incomplete-feature",
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<2 lines>...
        help="Enable support of incomplete/experimental features for early preview",
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/data/.pyenv/versions/3.14.0b1/lib/python3.14/argparse.py", line 1562, in add_argument
    formatter = self._get_formatter()
  File "/data/.pyenv/versions/3.14.0b1/lib/python3.14/argparse.py", line 2729, in _get_formatter
    return self.formatter_class(
           ~~~~~~~~~~~~~~~~~~~~^
        prog=self.prog,
        ^^^^^^^^^^^^^^^
        prefix_chars=self.prefix_chars,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        color=self.color,
        ^^^^^^^^^^^^^^^^^
    )
    ^
TypeError: AugmentedHelpFormatter.__init__() got an unexpected keyword argument 'prefix_chars'.)

To Reproduce

  1. setup a python 3.14 environment
  2. run mypy --version

Your Environment

  • Mypy version used: 1.15.0
  • Mypy command-line flags: --version
  • Mypy configuration options from mypy.ini (and other config files): n/a
  • Python version used: 3.1.4.0b1
  • Operating system and version: Linux

Activity

A5rocks

A5rocks commented on May 26, 2025

@A5rocks
Collaborator

This should be fixed by #19020 which should be in mypy 1.16

kasium

kasium commented on May 26, 2025

@kasium
Author

Thanks a lot!

brianschubert

brianschubert commented on Jun 21, 2025

@brianschubert
Collaborator

Note for posterity: this was also patched upstream for 3.14.0b2+

python/cpython#133653

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @kasium@brianschubert@A5rocks

        Issue actions

          mypy crashes with python 3.14 within argparse · Issue #19150 · python/mypy