(Protocol + Protocol ... + Protocol + TypeVar) * overload = an optype paradigm? #785
Answered
by
jorenham
hunterhogan
asked this question in
Q&A
|
Is this more-or-less a primitive, simple use of the concepts in optype? As one of the only # Py 3.10
from typing import Protocol
from typing_extensions import Self
class Ordinals(Protocol):
"""Any Python `object` `type` that may be ordered before or after a comparable `object` `type` by comparison operators."""
def __le__(self: Self, not_self_selfButSelfSelf_youKnow: Self, /) -> bool:
"""Comparison by "***l***ess than or ***e***qual to"."""
...
def __lt__(self: Self, otherSelfWhichIsNotAnOxymoron: Self, /) -> bool:
"""Comparison by "***l***ess ***t***han"."""
...# Py 3.13
from humpy_cytoolz.functoolz import curry as syntacticCurry
from hunterMakesPy import Ordinals
@syntacticCurry
def between吗[小于: Ordinals](floor: 小于, ceiling: 小于, comparand: 小于) -> bool:
"""Inclusive `floor <= comparand <= ceiling`."""
return floor <= comparand <= ceiling
from mapFolding._e.filters import between吗
domain_r = tuple(filter(between吗(0, pile_k - inclusive), domain_r)) |
Answered by
jorenham
Jul 6, 2026
Replies: 1 comment 1 reply
|
At the core, optype consists of single-method (and some single-attribute) protocols. So in that sense your import optype as op
class Ordinals(op.CanLeSame[bool], op.CanLtSame[bool]): ...BTW, if Does that answer your question? |
1 reply
Answer selected by
hunterhogan
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
At the core, optype consists of single-method (and some single-attribute) protocols. So in that sense your
Ordinalsprotocol could be expressed (using some imaginary syntax) as something likeop.CanLe[Self, bool] & op.CanLt[Self, bool]. Once #650 is implemented, we could write this in valid Python asBTW, if
between吗is all thatOrdinalsis used for, then the__lt__shouldn't be necessary, and aop.CanLeSamewould suffice.Does that answer your question?