Raise a clear TypeError for non-str/non-bytes input to slugify()#183
Open
rantkiglorelgmx-lab wants to merge 2 commits into
Open
Raise a clear TypeError for non-str/non-bytes input to slugify()#183rantkiglorelgmx-lab wants to merge 2 commits into
rantkiglorelgmx-lab wants to merge 2 commits into
Conversation
added 2 commits
June 30, 2026 21:33
(cherry picked from commit 5804929c5a5d5fd07b3fd5d81af45c293fd0db54)
|
But the function is typed already and would be caught by type checkers. If a developer (or AI bot) is having trouble with "opaque errors" because of using the wrong type, then they could use a type checker themselves, instead of depending on all upstream dependencies to add |
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.
What
slugify()currently fails with an opaque error for input that is neitherstrnorbytes(e.g.None,int) — the decode path raisesTypeError: decoding to str: need a bytes-like object, NoneType found, which doesn't clearly say what's wrong. This adds an explicit, clear guard at the top of the function:Backward compatibility
Add-only — every input that previously worked is unaffected. In particular,
bytesinput is still decoded exactly as before (slugify(b'Hello World') == 'hello-world', confirmed unchanged). Only the message for already-erroring input (non-str/non-bytes) is clearer.Verification
assertRaisesRegex, and separately assertsbytesinput still slugifies correctly (regression lock).83 passed.Co-authored by Claude (Anthropic) as part of an automated hardening pass; independently re-verified (non-vacuity, backward-compatibility, coverage) before submission.