Skip to content

like() variants#252

Merged
cjw296 merged 11 commits into
mainfrom
like-variants/human
Jul 1, 2026
Merged

like() variants#252
cjw296 merged 11 commits into
mainfrom
like-variants/human

Conversation

@cjw296

@cjw296 cjw296 commented Jul 1, 2026

Copy link
Copy Markdown
Member

No description provided.

cjw296 and others added 11 commits June 29, 2026 09:27
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>
@cjw296 cjw296 force-pushed the like-variants/human branch from 9de1edc to cc7307a Compare July 1, 2026 09:55
@cjw296 cjw296 merged commit 3d411cf into main Jul 1, 2026
35 checks passed
@cjw296 cjw296 deleted the like-variants/human branch July 1, 2026 10:01
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.

1 participant