Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
beartype.vale.Is[...]
+ __call__()
x 1.
This commit is the first in a commit chain generalizing the `beartype.vale.Is[...]` validator factory to accept **callable objects** (i.e., high-level pure-Python objects whose classes define the `__call__()` dunder method, rendering those objects callable), en-route to resolving feature request #360 kindly submitted by "Computer Graphics and Visualization" sufferer @sylvorg, who graciously sacrificed his entire undergraduate GPA for the gradual betterment of @beartype. Your journey of woe and hardship will *not* be forgotten, @sylvorg! Specifically, @beartype now accepts class-based beartype validators resembling: ```python from beartype.door import is_bearable from beartype.typing import Annotated from beartype.vale import Is from functools import partial class TruthSeeker(object): def __call__(self, obj: object) -> bool: ''' Tester method returning :data:`True` only if the passed object evaluates to :data:`True` when coerced into a boolean and whose first parameter is ignorable. ''' return bool(obj) # Beartype validator matching only objects that evaluate to "True". Truthy = Annotated[object, Is[TruthSeeker()]] assert is_bearable('', Truthy) is False assert is_bearable('Even lies are true now, huh?', Truthy) is True ``` Is this valuable? I have no idea. Let's pretend I did something useful tonight so that I can sleep without self-recrimination. (*Pungent puns, gentlemen!*)
- Loading branch information
Showing
13 changed files
with
635 additions
and
253 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.