Skip to content

FIX Reject multi-character and empty punctuation_list entries in InsertPunctuationConverter - #3294

Merged
Roman Lutz (romanlutz) merged 2 commits into
microsoft:mainfrom
ShivamSharma43:fix/insert-punctuation-list-validation
Oct 18, 2026
Merged

Roman Lutz (romanlutz) merged 2 commits into
microsoft:mainfrom
ShivamSharma43:fix/insert-punctuation-list-validation

Conversation

@ShivamSharma43

Copy link
Copy Markdown
Contributor

Description

Fixes #3292.

InsertPunctuationConverter validated punctuation_list with char in string.punctuation, which is a substring test. Runs that happen to be contiguous in string.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 with IndexError: Cannot choose from an empty sequence.

_is_valid_punctuation now requires a non-empty list whose entries are each a single character from string.punctuation, so all of these raise the documented ValueError: Invalid punctuations: .... Lists that were already valid, and the default list, behave exactly as before. The convert_async docstring now lists this ValueError.

Tests and Documentation

  • New parametrized test_punctuation_list_rejects_substrings_of_string_punctuation covers ["()"], ["<=>"], ["{|}"], [""], [",", "!?"] and []. On main, 5 of the 6 cases fail; "!?" is not contiguous in string.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 format and ty check pass on the changed files. git diff --check is clean.
  • No documentation changes. JupyText not run, since the converter docs do not pass invalid punctuation lists.

🤖 Generated with Claude Code

…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>
Copilot AI balanced review requested due to automatic review settings October 17, 2026 18:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@romanlutz
Roman Lutz (romanlutz) added this pull request to the merge queue Oct 18, 2026
Merged via the queue into microsoft:main with commit e6329b5 Oct 18, 2026
64 checks passed
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: InsertPunctuationConverter accepts multi-character and empty punctuation_list entries

3 participants