Skip to content

Fix #19491, crash when using enable_error_code value of wrong type in pyproject.toml #19494

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

wyattscarpenter
Copy link
Contributor

@wyattscarpenter wyattscarpenter commented Jul 24, 2025

Fixes #19491

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 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.

I have added a (fairly minimal) test for this behavior.

Copy link
Contributor

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

elif isinstance(v, Sequence):
return [p.strip() if isinstance(p, str) else p for p in v]
else:
return v
Copy link
Collaborator

Choose a reason for hiding this comment

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

To keep the blast radius minimal, maybe

Suggested change
return v
raise argparse.ArgumentTypeError(f"Expected a list or a stringified version thereof, but got: '{v}'")

Copy link
Collaborator

Choose a reason for hiding this comment

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

Then you won't need Any in return type too

Copy link
Contributor Author

@wyattscarpenter wyattscarpenter Jul 25, 2025

Choose a reason for hiding this comment

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

A fine suggestion! If we're going this route with it, I can also check the type in the list comprehension as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Config validation is always helpful, let's try to do such easy checks to avoid crashes down the road. It isn't performance-critical (we only check a handful of items and only do that once per run) so shouldn't do any harm

@wyattscarpenter wyattscarpenter marked this pull request as draft July 26, 2025 01:12
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.

Crash when using an invalid 'enable_error_code' value in pyproject.toml
2 participants