Skip to content

fix: capture mypy stderr output on fatal options error instead of generic message#828

Open
sbrunner wants to merge 3 commits into
prospector-dev:masterfrom
sbrunner:fix-mypy-options-error-825
Open

fix: capture mypy stderr output on fatal options error instead of generic message#828
sbrunner wants to merge 3 commits into
prospector-dev:masterfrom
sbrunner:fix-mypy-options-error-825

Conversation

@sbrunner

@sbrunner sbrunner commented Jul 2, 2026

Copy link
Copy Markdown
Member

Description

Example of new output:

************* Module .
.:0:0: fatal-options-error(mypy): usage: mypy [-h] [-v] [-V] [more options; see below]
            [-m MODULE] [-p PACKAGE] [-c PROGRAM_TEXT] [files ...]
mypy: error: argument --python-version: Python 3.9 is not supported (must be 3.10 or higher)

Check Information
=================
         Started: 2026-07-02 11:47:24.052039
        Finished: 2026-07-02 11:47:24.214779
      Time Taken: 0.16 seconds
       Formatter: pylint
        Profiles: .prospector.yaml, utils:base, utils:base-all, strictness_none, member_warnings, utils:no-design-checks, utils:fix, duplicated, duplicated:ruff, duplicated:black, duplicated:isort, no_doc_warnings, no_test_warnings
      Strictness: from profile
  Libraries Used: 
       Tools Run: mypy
  Messages Found: 1

Related Issue

Probably fix: #825 I don't have the exact same issue.

Motivation and Context

How Has This Been Tested?

Run in a project that has a mypy error

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • My change requires a change to the dependencies
  • I have updated the dependencies accordingly
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@sbrunner sbrunner force-pushed the fix-mypy-options-error-825 branch from 63b4767 to 6cbb1f8 Compare July 2, 2026 09:41
@sbrunner sbrunner force-pushed the fix-mypy-options-error-825 branch from f011f27 to 99b08ba Compare July 2, 2026 09:46

@carlio carlio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks like it's repeating some things already done with the stdout/stderr capturing - https://github.com/prospector-dev/prospector/blob/master/prospector/run.py#L110

Am I missing something? What does this PR add that isn't already available via the --die-on-tool-error or --direct-tool-stdout options?

Is there a way to capture the stderr using the exising mechanism instead of repeating it?

@sbrunner

sbrunner commented Jul 3, 2026

Copy link
Copy Markdown
Member Author

Yes your right it's not so good, do you like like this, to get:

.: failure(mypy): Tool mypy failed to run , with stderr:
usage: mypy [-h] [-v] [-V] [more options; see below]
            [-m MODULE] [-p PACKAGE] [-c PROGRAM_TEXT] [files ...]
mypy: error: argument --python-version: Python 3.0 is not supported (must be 3.10 or higher)
(exception was raised, re-run prospector with -X to see the stacktrace)

Or should we propose to use the option --die-on-tool-error to get:

usage: mypy [-h] [-v] [-V] [more options; see below]
           [-m MODULE] [-p PACKAGE] [-c PROGRAM_TEXT] [files ...]
mypy: error: argument --python-version: Python 3.0 is not supported (must be 3.10 or higher)
************* Module .
.: failure(mypy): Tool mypy failed to run (exception was raised, re-run prospector with -X to see the stacktrace)

@sbrunner sbrunner force-pushed the fix-mypy-options-error-825 branch from deb6ed5 to e04d8ae Compare July 3, 2026 09:16
@carlio

carlio commented Jul 3, 2026

Copy link
Copy Markdown
Member

I asked the reporter for the output from --die-on-tool-error, let's see if they reply, but it might help understand what the issue is - the current version you have looks good I think but let's wait to get extra information from the person who can reproduce it. Unless they never reply then we just merge anyway and hope :)

@sbrunner

sbrunner commented Jul 3, 2026

Copy link
Copy Markdown
Member Author

The --die-on-tool-error returns that (if we removes the try in mypy):

Traceback (most recent call last):
 File "/home/sbrunner/.pyenv/versions/3.13.9/lib/python3.13/argparse.py", line 2551, in _get_value
   result = type_func(arg_string)
 File "mypy/config_parser.py", line 53, in parse_version
mypy.config_parser.VersionTypeError: Python 3.0 is not supported (must be 3.10 or higher)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
 File "/home/sbrunner/.pyenv/versions/3.13.9/lib/python3.13/argparse.py", line 1937, in _parse_known_args2
   namespace, args = self._parse_known_args(args, namespace, intermixed)
                     ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/home/sbrunner/.pyenv/versions/3.13.9/lib/python3.13/argparse.py", line 2188, in _parse_known_args
   start_index = consume_optional(start_index)
 File "/home/sbrunner/.pyenv/versions/3.13.9/lib/python3.13/argparse.py", line 2112, in consume_optional
   take_action(action, args, option_string)
   ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/home/sbrunner/.pyenv/versions/3.13.9/lib/python3.13/argparse.py", line 1998, in take_action
   argument_values = self._get_values(action, argument_strings)
 File "/home/sbrunner/.pyenv/versions/3.13.9/lib/python3.13/argparse.py", line 2518, in _get_values
   value = self._get_value(action, arg_string)
 File "/home/sbrunner/.pyenv/versions/3.13.9/lib/python3.13/argparse.py", line 2556, in _get_value
   raise ArgumentError(action, msg)
argparse.ArgumentError: argument --python-version: Python 3.0 is not supported (must be 3.10 or higher)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
 File "/home/sbrunner/workspace-ai/prospector/prospector/run.py", line 94, in execute
   messages += tool.run(found_files)
               ~~~~~~~~^^^^^^^^^^^^^
 File "/home/sbrunner/workspace-ai/prospector/prospector/tools/mypy/__init__.py", line 125, in run
   return self._run_std(args)
          ~~~~~~~~~~~~~^^^^^^
 File "/home/sbrunner/workspace-ai/prospector/prospector/tools/mypy/__init__.py", line 129, in _run_std
   sources, options = mypy.main.process_options(args, fscache=self.fscache)
                      ~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "mypy/main.py", line 1436, in process_options
 File "/home/sbrunner/.pyenv/versions/3.13.9/lib/python3.13/argparse.py", line 1898, in parse_args
   args, argv = self.parse_known_args(args, namespace)
                ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
 File "/home/sbrunner/.pyenv/versions/3.13.9/lib/python3.13/argparse.py", line 1908, in parse_known_args
   return self._parse_known_args2(args, namespace, intermixed=False)
          ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 File "/home/sbrunner/.pyenv/versions/3.13.9/lib/python3.13/argparse.py", line 1939, in _parse_known_args2
   self.error(str(err))
   ~~~~~~~~~~^^^^^^^^^^
 File "mypy/main.py", line 450, in error
 File "mypy/main.py", line 437, in exit
SystemExit: 2

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
 File "/home/sbrunner/.pyenv/versions/3.13.9/bin/prospector", line 7, in <module>
   sys.exit(main())
            ~~~~^^
 File "/home/sbrunner/workspace-ai/prospector/prospector/run.py", line 207, in main
   prospector.execute()
   ~~~~~~~~~~~~~~~~~~^^
 File "/home/sbrunner/workspace-ai/prospector/prospector/run.py", line 112, in execute
   raise FatalProspectorException(f"Tool {toolname} failed to run.") from ex
prospector.exceptions.FatalProspectorException: Tool mypy failed to run.

It's useful to debug but its hart to read and we don't get the error message!

PS: I edit my last message because I write --die-on-tool-error in place of --direct-tool-stdout!

@mdabrowski1990

mdabrowski1990 commented Jul 10, 2026

Copy link
Copy Markdown

I am facing the same issue in my repo - 100% reproducible on python 3.14
Feel free to share potential fixes for testing or simply clone https://github.com/mdabrowski1990/uds (dependencies are in pyproject.toml)

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.

[BUG] Weird mypy error at "line 0" in python 3.14

3 participants