You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Crash when using an invalid 'enable_error_code' value in pyproject.toml #19491
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
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.
Activity
wyattscarpenter commentedon Jul 24, 2025
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 likeTypeError: '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.
Fix python#19491, crash when using enable_error_code value of wrong t…
Fix crash when using enable_error_code value of wrong type in pyproje…