Skip to content

Crash when using an invalid 'enable_error_code' value in pyproject.toml #19491

Closed

Description

@Spacerulerwill

Crash Report

Running mypy . causes an unhandled exception when providing invalid input for the enable_error_code mypy setting in pyproject.toml only. This doesn't happen with the equivalent config in mypy.ini or via the command line, see extra notes at the bottom.

Traceback

Traceback (most recent call last):
  File "/home/william/mypytest/.venv/bin/mypy", line 10, in <module>
    sys.exit(console_entry())
             ~~~~~~~~~~~~~^^
  File "/home/william/mypytest/.venv/lib/python3.13/site-packages/mypy/__main__.py", line 15, in console_entry
    main()
    ~~~~^^
  File "mypy/main.py", line 89, in main
  File "mypy/main.py", line 1365, in process_options
  File "mypy/config_parser.py", line 330, in parse_config_file
  File "mypy/config_parser.py", line 558, in parse_section
  File "mypy/config_parser.py", line 221, in <lambda>
  File "mypy/config_parser.py", line 70, in try_split
TypeError: 'bool' object is not iterable

To Reproduce

pyproject.toml

[project]
name = "mypy-bug-test"
version = "0.1.0"
dependencies = [
    "mypy==1.17.0"
]

[tool.mypy]
enable_error_code = true

Run

python -m venv .venv 
source .venv/bin/activate
pip install .
mypy .

Your Environment

  • Mypy version used: 1.17.0
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): enable_error_code = true
  • Python version used: 3.13.5
  • Operating system and version: AlmaLinux 9.6

Extra Notes
When using an equivalent mypy.ini file:

[mypy]
enable_error_code = true

The output is:

mypy.ini: [mypy]: enable_error_code: Invalid error code(s): true
There are no .py[i] files in directory '.'

When adding the parameter via the command line: mypy . --enable-error-code true, the output is:

usage: mypy [-h] [-v] [-V] [more options; see below]
            [-m MODULE] [-p PACKAGE] [-c PROGRAM_TEXT] [files ...]
mypy: error: Invalid error code(s): true

Activity

  1. wyattscarpenter commented on Jul 24, 2025

    @wyattscarpenter
    Contributor

    I was able to reproduce this on the current tip of master. If you give a string in toml, you get Invalid error code(s): whatever. However, if you give a value that doesn't mean a string in toml, you get a crash like TypeError: 'int' object is not iterable. I didn't investigate ini but I imagine it's looser about what it considers a string.

    Appendix A: examples of what I just said:

    [tool.mypy]
    enable_error_code = 2

    TypeError: 'int' object is not iterable

    [tool.mypy]
    enable_error_code = "whatever"

    Invalid error code(s): whatever

    I suspect this would also apply to many other pyproject.toml values if you set them wrong, because we pass many of them immediately into try_split, which tries to iterate them.

  2. added a commit that references this issue on Jul 24, 2025
    10df788
  3. added a commit that references this issue on Aug 8, 2025
    a6bfb2e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions