Skip to content

Commit

Permalink
changed capitalization of CanA* async methods, analogous to the ref…
Browse files Browse the repository at this point in the history
…lected binops
  • Loading branch information
jorenham committed Feb 26, 2024
1 parent ed06917 commit dbbc18a
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 18 deletions.
16 changes: 8 additions & 8 deletions optype/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
__all__ = (
'CanAEnter',
'CanAExit',
'CanAIter',
'CanANext',
'CanAbs',
'CanAdd',
'CanAenter',
'CanAexit',
'CanAiter',
'CanAnd',
'CanAnext',
'CanAsyncWith',
'CanAwait',
'CanBool',
Expand Down Expand Up @@ -122,13 +122,13 @@
from importlib import metadata as _metadata

from ._can import (
CanAEnter,
CanAExit,
CanAIter,
CanANext,
CanAbs,
CanAdd,
CanAenter,
CanAexit,
CanAiter,
CanAnd,
CanAnext,
CanAsyncWith,
CanAwait,
CanBool,
Expand Down
10 changes: 5 additions & 5 deletions optype/_can.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,23 +511,23 @@ def __await__(self: 'CanAwait[V]') -> Generator[_MaybeFuture, None, V]: ...
# https://docs.python.org/3/reference/datamodel.html#asynchronous-iterators

@runtime_checkable
class CanAnext[V](Protocol):
class CanANext[V](Protocol):
def __anext__(self) -> V: ...

@runtime_checkable
class CanAiter[Y: CanAnext[Any]](Protocol):
class CanAIter[Y: CanANext[Any]](Protocol):
def __aiter__(self) -> Y: ...


# 3.4.4. Asynchronous Context Managers
# https://docs.python.org/3/reference/datamodel.html#asynchronous-context-managers

@runtime_checkable
class CanAenter[V](Protocol):
class CanAEnter[V](Protocol):
def __aenter__(self) -> CanAwait[V]: ...

@runtime_checkable
class CanAexit[R](Protocol):
class CanAExit[R](Protocol):
@overload
def __aexit__(
self,
Expand All @@ -544,7 +544,7 @@ def __aexit__[E: BaseException](
) -> CanAwait[R]: ...

@runtime_checkable
class CanAsyncWith[V, R](CanAenter[V], CanAexit[R], Protocol): ...
class CanAsyncWith[V, R](CanAEnter[V], CanAExit[R], Protocol): ...


# standard library `copy`
Expand Down
74 changes: 69 additions & 5 deletions optype/_does.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,77 @@ def __call__[X, Y](self, __o: _c.CanIOr[X, Y], __x: X, /) -> Y: ...


# unary arithmetic
# TODO: neg, pos, abs, invert

# indexing
# TODO: hash, index
@final
class DoesNeg(Protocol):
def __call__[Y](self, __o: _c.CanNeg[Y], /) -> Y: ...

@final
class DoesPos(Protocol):
def __call__[Y](self, __o: _c.CanPos[Y], /) -> Y: ...

@final
class DoesAbs(Protocol):
def __call__[Y](self, __o: _c.CanAbs[Y], /) -> Y: ...

@final
class DoesInvert(Protocol):
def __call__[Y](self, __o: _c.CanInvert[Y], /) -> Y: ...


# fingerprinting

@final
class DoesHash(Protocol):
def __call__[Y](self, __o: _c.CanHash, /) -> int: ...

@final
class DoesIndex(Protocol):
def __call__[Y](self, __o: _c.CanIndex, /) -> int: ...


# rounding
# TODO: round, trunc, floor, ceil

@final
class DoesRound(Protocol):
@overload
def __call__[Y](self, __o: _c.CanRound1[Y], /) -> Y: ...
@overload
def __call__[N, Y](self, __o: _c.CanRound2[N, Y], __n: N, /) -> Y: ...

@final
class DoesTrunc(Protocol):
def __call__[Y](self, __o: _c.CanTrunc[Y], /) -> Y: ...

@final
class DoesFloor(Protocol):
def __call__[Y](self, __o: _c.CanFloor[Y], /) -> Y: ...

@final
class DoesCeil(Protocol):
def __call__[Y](self, __o: _c.CanCeil[Y], /) -> Y: ...


# async iteration
# TODO: aiter, anext

@final
class DoesANext(Protocol):
# https://docs.python.org/3/library/functions.html#next
@overload
def __call__[V](self, __vs: _c.CanNext[V], /) -> V: ...
@overload
def __call__[V, V0](self, __vs: _c.CanNext[V], __v0: V0, /) -> V | V0: ...

@final
class DoesAIter(Protocol):
# https://docs.python.org/3/library/functions.html#iter
@overload
def __call__[Vs: _c.CanNext[Any]](self, __vs: _c.CanIter[Vs], /) -> Vs: ...
@overload
def __call__[V](
self, __vs: _c.CanGetitem[_c.CanIndex, V], /,
) -> _c.CanIterNext[V]: ...
@overload
def __call__[V, S: object | None](
self, __f: _c.CanCall[[], V | S], __s: S, /,
) -> _c.CanIterNext[V]: ...

0 comments on commit dbbc18a

Please sign in to comment.