fix: handle non-string input in Replace validator gracefully#540
Open
gaoflow wants to merge 1 commit into
Open
fix: handle non-string input in Replace validator gracefully#540gaoflow wants to merge 1 commit into
gaoflow wants to merge 1 commit into
Conversation
Replace.__call__ passed non-string values straight to re.Pattern.sub(), which raises an unhandled TypeError. Wrap it and raise MatchInvalid (honouring a custom msg), matching how Match reports the same case.
gaoflow
force-pushed
the
fix/replace-non-string-typeerror
branch
from
July 15, 2026 08:16
7ade908 to
4c75e63
Compare
Contributor
Author
|
Rebased onto master and dropped the unrelated quote-style churn from the diff — it's now just the Replace fix and its test. |
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.
The Replace validator calls re.Pattern.sub() directly on the input value. When passed a non-string type (int, None, list, etc.), this raises an unhandled TypeError instead of the expected Invalid exception.
This matches the behavior of the Match validator, which already catches TypeError and raises a proper Invalid error with a descriptive message.
Before (crashes):
After:
Changes: