like() variants#252
Merged
Merged
Conversation
Saves recompiling a pattern you already have, and lets you reuse a pattern compiled with flags that aren't expressible by name.
So strictly-typed code can express a regex match inline without an explicit StringComparison and the type-ignore that needs.
Useful for objects whose type doesn't support meaningful equality but whose repr is stable and worth pinning.
Frees up the Str* naming space for a StrComparison sibling to ReprComparison, and names the class for what it stands in for (text) rather than how it matches (regex).
The str()/repr() pair: same type-plus-rendering check, for objects whose str() is the stable thing worth asserting.
Subclasses render differently and usually mean a different object, so an exact type check is the safer default; reach for a plain Comparison when subclass matching is wanted. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
These mirror like(): they build a ReprComparison or StrComparison but are typed to return the compared type, so they slot into strictly typed code. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…bjects The flat Comparisons dump didn't reflect the matchers/objects split, so the on-this-page index read as noise. Split it into three sections, surface the comparers under Comparing, drop the render member from the Repr/Str classes, and document the five compare_* comparers that had been missed. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
So you can assert a raised exception's type and repr or str with repr_like and str_like without building the exception instance by hand. A wrong type still propagates the original exception, matching how ShouldRaise treats a mismatched type elsewhere. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
9de1edc to
cc7307a
Compare
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.
No description provided.