Repository navigation
FIX Reject multi-character and empty punctuation_list entries in InsertPunctuationConverter - #3294
Merged
Roman Lutz (romanlutz) merged 2 commits intoOct 18, 2026
Conversation
…rtPunctuationConverter _is_valid_punctuation used a substring test, so runs such as "()" or "<=>", the empty string and an empty list passed validation. Require a non-empty list of single characters from string.punctuation. Fixes microsoft#3292 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Roman Lutz (romanlutz)
approved these changes
Oct 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #3292.
InsertPunctuationConvertervalidatedpunctuation_listwithchar in string.punctuation, which is a substring test. Runs that happen to be contiguous instring.punctuation, such as"()"or"<=>", were accepted and inserted as-is, the empty string was accepted and inserted nothing, and an empty list passed validation and then failed withIndexError: Cannot choose from an empty sequence._is_valid_punctuationnow requires a non-empty list whose entries are each a single character fromstring.punctuation, so all of these raise the documentedValueError: Invalid punctuations: .... Lists that were already valid, and the default list, behave exactly as before. Theconvert_asyncdocstring now lists thisValueError.Tests and Documentation
test_punctuation_list_rejects_substrings_of_string_punctuationcovers["()"],["<=>"],["{|}"],[""],[",", "!?"]and[]. Onmain, 5 of the 6 cases fail;"!?"is not contiguous instring.punctuation, so it was already rejected and stays as a regression case. With this change, all of them pass.pytest tests/unit/converter/test_insert_punctuation_converter.py: 23 passed.pytest tests/unit/converter: 2732 passed, 34 skipped.ruff check,ruff formatandty checkpass on the changed files.git diff --checkis clean.🤖 Generated with Claude Code