Skip to content

numerary.types package reference

Experimental

This package is an attempt to ease compatibility between Python’s numbers and types. If that sounds like it shouldn’t be a thing, you won’t get any argument out of me. Anyhoo, this package should be considered experimental. I am working toward stability as quickly as possible, but be warned that future release may introduce incompatibilities or remove this package altogether. Feedback, suggestions, and contributions are desperately appreciated.

RationalLike

Bases: SupportsAbs[_T_co], SupportsFloat, SupportsNumeratorDenominator, SupportsRealOps[_T_co], SupportsComplexOps[_T_co], SupportsComplexPow, Protocol, Generic[_T_co]

A caching ABC that defines a core set of operations for interacting with rationals. It is a composition of:

Basically:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
from typing TypeVar, runtime_checkable
from beartype.typing import Protocol
from numerary.types import CachingProtocolMeta, Supports
T_co = TypeVar("T_co", covariant=True)

@runtime_checkable
class RationalLike(
  SupportsAbs[T_co],
  SupportsFloat,
  SupportsNumeratorDenominator,
  SupportsRealOps[T_co],
  SupportsComplexOps[T_co],
  SupportsComplexPow[T_co],
  Protocol[T_co],
  metaclass=CachingProtocolMeta,
):
  @abstractmethod
  def __hash__(self) -> int:
    pass

This is intended as a practically useful, but incomplete list. To enforce equivalence to numbers.Rational, one would also need:

Source code in numerary/types.py
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
@runtime_checkable
class RationalLike(
    SupportsAbs[_T_co],
    SupportsFloat,
    SupportsNumeratorDenominator,
    SupportsRealOps[_T_co],
    SupportsComplexOps[_T_co],
    SupportsComplexPow,
    Protocol,
    Generic[_T_co],
    metaclass=CachingProtocolMeta,
):
    r"""
    A caching ABC that defines a core set of operations for interacting with rationals.
    It is a composition of:

    * [``SupportsAbs``][numerary.types.SupportsAbs]
    * [``SupportsFloat``][numerary.types.SupportsFloat]
    * [``SupportsNumeratorDenominator``][numerary.types.SupportsNumeratorDenominator]
    * [``SupportsRealOps``][numerary.types.SupportsRealOps]
    * [``SupportsComplexOps``][numerary.types.SupportsComplexOps]
    * [``SupportsComplexPow``][numerary.types.SupportsComplexPow]
    * a ``__hash__`` method

    Basically:

    ``` python
    from typing TypeVar, runtime_checkable
    from beartype.typing import Protocol
    from numerary.types import CachingProtocolMeta, Supports…
    T_co = TypeVar("T_co", covariant=True)

    @runtime_checkable
    class RationalLike(
      SupportsAbs[T_co],
      SupportsFloat,
      SupportsNumeratorDenominator,
      SupportsRealOps[T_co],
      SupportsComplexOps[T_co],
      SupportsComplexPow[T_co],
      Protocol[T_co],
      metaclass=CachingProtocolMeta,
    ):
      @abstractmethod
      def __hash__(self) -> int:
        pass
    ```

    This is intended as a practically useful, but incomplete list. To enforce
    equivalence to ``#!python numbers.Rational``, one would also need:

    * [``SupportsComplex``][numerary.types.SupportsComplex]
    * [``SupportsConjugate``][numerary.types.SupportsConjugate]
    * [``SupportsRealImag``][numerary.types.SupportsRealImag]
    * [``SupportsRound``][numerary.types.SupportsRound]
    * [``SupportsTrunc``][numerary.types.SupportsTrunc]
    * [``SupportsFloorCeil``][numerary.types.SupportsFloorCeil]
    * [``SupportsDivmod``][numerary.types.SupportsDivmod]
    """

    # Must be able to instantiate it
    @abstractmethod
    def __init__(self, *args: Any, **kw: Any):
        pass

    @abstractmethod
    def __hash__(self) -> int:
        pass

RationalLikeMethods

Bases: SupportsAbs[_T_co], SupportsFloat, SupportsNumeratorDenominatorMethods, SupportsRealOps[_T_co], SupportsComplexOps[_T_co], SupportsComplexPow, Protocol, Generic[_T_co]

A caching ABC that defines a core set of operations for interacting with rationals. It is identical to RationalLike with one important exception. Instead of SupportsNumeratorDenominator, this protocol provides SupportsNumeratorDenominatorMethods.

Basically:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
from typing TypeVar, runtime_checkable
from beartype.typing import Protocol
from numerary.types import CachingProtocolMeta, Supports
T_co = TypeVar("T_co", covariant=True)

@runtime_checkable
class RationalLikeMethods(
  SupportsAbs[T_co],
  SupportsFloat,
  SupportsNumeratorDenominatorMethods,
  SupportsRealOps[T_co],
  SupportsComplexOps[T_co],
  SupportsComplexPow[T_co],
  Protocol[T_co],
  metaclass=CachingProtocolMeta,
):
  @abstractmethod
  def __hash__(self) -> int:
    pass

This is probably not very useful on its own, but is important to the construction of RationalLikeMixedU and RationalLikeMixedT.

See also the numerator and denominator helper functions.

Source code in numerary/types.py
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
@runtime_checkable
class RationalLikeMethods(
    SupportsAbs[_T_co],
    SupportsFloat,
    SupportsNumeratorDenominatorMethods,
    SupportsRealOps[_T_co],
    SupportsComplexOps[_T_co],
    SupportsComplexPow,
    Protocol,
    Generic[_T_co],
    metaclass=CachingProtocolMeta,
):
    r"""
    A caching ABC that defines a core set of operations for interacting with rationals.
    It is identical to [``RationalLike``][numerary.types.RationalLike] with one
    important exception. Instead of
    [``SupportsNumeratorDenominator``][numerary.types.SupportsNumeratorDenominator],
    this protocol provides
    [``SupportsNumeratorDenominatorMethods``][numerary.types.SupportsNumeratorDenominatorMethods].

    Basically:

    ``` python
    from typing TypeVar, runtime_checkable
    from beartype.typing import Protocol
    from numerary.types import CachingProtocolMeta, Supports…
    T_co = TypeVar("T_co", covariant=True)

    @runtime_checkable
    class RationalLikeMethods(
      SupportsAbs[T_co],
      SupportsFloat,
      SupportsNumeratorDenominatorMethods,
      SupportsRealOps[T_co],
      SupportsComplexOps[T_co],
      SupportsComplexPow[T_co],
      Protocol[T_co],
      metaclass=CachingProtocolMeta,
    ):
      @abstractmethod
      def __hash__(self) -> int:
        pass
    ```

    This is probably not very useful on its own, but is important to the construction of
    [``RationalLikeMixedU``][numerary.types.RationalLikeMixedU] and
    [``RationalLikeMixedT``][numerary.types.RationalLikeMixedT].

    See also the [``numerator``][numerary.types.numerator] and
    [``denominator``][numerary.types.denominator] helper functions.
    """

    # Must be able to instantiate it
    @abstractmethod
    def __init__(self, *args: Any, **kw: Any):
        pass

    @abstractmethod
    def __hash__(self) -> int:
        pass

SupportsAbs

Bases: _SupportsAbs[_T_co], Protocol, Generic[_T_co]

A derivative of beartype.typing.SupportsAbs with an override-able cache.

Source code in numerary/types.py
67
68
69
70
71
72
73
74
75
76
@runtime_checkable
class SupportsAbs(
    _SupportsAbs[_T_co],
    Protocol,
    Generic[_T_co],
    metaclass=CachingProtocolMeta,
):
    r"""
    A derivative of ``beartype.typing.SupportsAbs`` with an override-able cache.
    """

SupportsComplex

Bases: _SupportsComplex, Protocol

A derivative of beartype.typing.SupportsComplex with an override-able cache.

Source code in numerary/types.py
82
83
84
85
86
87
88
89
90
@runtime_checkable
class SupportsComplex(
    _SupportsComplex,
    Protocol,
    metaclass=CachingProtocolMeta,
):
    r"""
    A derivative of ``beartype.typing.SupportsComplex`` with an override-able cache.
    """

SupportsFloat

Bases: _SupportsFloat, Protocol

A derivative of beartype.typing.SupportsFloat with an override-able cache.

Source code in numerary/types.py
 96
 97
 98
 99
100
101
102
103
104
@runtime_checkable
class SupportsFloat(
    _SupportsFloat,
    Protocol,
    metaclass=CachingProtocolMeta,
):
    r"""
    A derivative of ``beartype.typing.SupportsFloat`` with an override-able cache.
    """

SupportsInt

Bases: _SupportsInt, Protocol

A derivative of beartype.typing.SupportsInt with an override-able cache.

Source code in numerary/types.py
110
111
112
113
114
115
116
117
118
@runtime_checkable
class SupportsInt(
    _SupportsInt,
    Protocol,
    metaclass=CachingProtocolMeta,
):
    r"""
    A derivative of ``beartype.typing.SupportsInt`` with an override-able cache.
    """

SupportsIndex

Bases: _SupportsIndex, Protocol

A derivative of beartype.typing.SupportsIndex with an override-able cache.

Source code in numerary/types.py
124
125
126
127
128
129
130
131
132
@runtime_checkable
class SupportsIndex(
    _SupportsIndex,
    Protocol,
    metaclass=CachingProtocolMeta,
):
    r"""
    A derivative of ``beartype.typing.SupportsIndex`` with an override-able cache.
    """

SupportsRound

Bases: _SupportsRound[_T_co], Protocol, Generic[_T_co]

A derivative of beartype.typing.SupportsRound with an override-able cache.

Source code in numerary/types.py
138
139
140
141
142
143
144
145
146
147
@runtime_checkable
class SupportsRound(
    _SupportsRound[_T_co],
    Protocol,
    Generic[_T_co],
    metaclass=CachingProtocolMeta,
):
    r"""
    A derivative of ``beartype.typing.SupportsRound`` with an override-able cache.
    """

SupportsConjugate

Bases: _SupportsConjugate, Protocol

A caching ABC defining the conjugate method.

(_SupportsConjugate is the raw, non-caching version that defines the actual methods.)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
>>> from typing import TypeVar
>>> from numerary.types import SupportsConjugate
>>> MyConjugateT = TypeVar("MyConjugateT", bound=SupportsConjugate)

>>> def conjugate_my_thing(arg: MyConjugateT) -> MyConjugateT:
...   assert isinstance(arg, SupportsConjugate)
...   return arg.conjugate()

>>> conjugate_my_thing(3)
3

>>> from decimal import Decimal
>>> conjugate_my_thing(Decimal(2.5))
Decimal('2.5')

>>> import sympy
>>> conjugate_my_thing(sympy.Float(3.5))
3.5
>>> type(_)
<class 'sympy.core.numbers.Float'>

>>> # error: Value of type variable "MyConjugateT" of "conjugate_my_thing" cannot be "str"
>>> conjugate_my_thing("not-a-number")  # type: ignore [type-var]
Traceback (most recent call last):
  ...
AssertionError
Source code in numerary/types.py
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
@runtime_checkable
class SupportsConjugate(
    _SupportsConjugate,
    Protocol,
    metaclass=CachingProtocolMeta,
):
    r"""
    A caching ABC defining the [``conjugate``
    method](https://docs.python.org/3/library/numbers.html#numbers.Complex.conjugate).

    ([``_SupportsConjugate``][numerary.types._SupportsConjugate] is the raw, non-caching
    version that defines the actual methods.)

    ``` python
    >>> from typing import TypeVar
    >>> from numerary.types import SupportsConjugate
    >>> MyConjugateT = TypeVar("MyConjugateT", bound=SupportsConjugate)

    >>> def conjugate_my_thing(arg: MyConjugateT) -> MyConjugateT:
    ...   assert isinstance(arg, SupportsConjugate)
    ...   return arg.conjugate()

    >>> conjugate_my_thing(3)
    3

    >>> from decimal import Decimal
    >>> conjugate_my_thing(Decimal(2.5))
    Decimal('2.5')

    >>> import sympy
    >>> conjugate_my_thing(sympy.Float(3.5))
    3.5
    >>> type(_)
    <class 'sympy.core.numbers.Float'>

    >>> # error: Value of type variable "MyConjugateT" of "conjugate_my_thing" cannot be "str"
    >>> conjugate_my_thing("not-a-number")  # type: ignore [type-var]
    Traceback (most recent call last):
      ...
    AssertionError

    ```
    """

SupportsRealImag

Bases: _SupportsRealImag, Protocol

A caching ABC defining the real and imag properties.

(_SupportsRealImag is the raw, non-caching version that defines the actual methods.)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
>>> from typing import Any, Tuple, TypeVar
>>> from numerary.types import SupportsRealImag, real, imag
>>> MyRealImagT = TypeVar("MyRealImagT", bound=SupportsRealImag)

>>> def real_imag_my_thing(arg: MyRealImagT) -> Tuple[Any, Any]:
...   assert isinstance(arg, SupportsRealImag)
...   return (real(arg), imag(arg))

>>> real_imag_my_thing(3)
(3, 0)

>>> from decimal import Decimal
>>> real_imag_my_thing(Decimal(2.5))
(Decimal('2.5'), Decimal('0'))

>>> # error: Value of type variable "MyRealImagT" of "real_imag_my_thing" cannot be "str"
>>> real_imag_my_thing("not-a-number")  # type: ignore [type-var]
Traceback (most recent call last):
  ...
AssertionError
Source code in numerary/types.py
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
@runtime_checkable
class SupportsRealImag(
    _SupportsRealImag,
    Protocol,
    metaclass=CachingProtocolMeta,
):
    r"""
    A caching ABC defining the
    [``real``](https://docs.python.org/3/library/numbers.html#numbers.Complex.real) and
    [``imag``](https://docs.python.org/3/library/numbers.html#numbers.Complex.imag)
    properties.

    ([``_SupportsRealImag``][numerary.types._SupportsRealImag] is
    the raw, non-caching version that defines the actual methods.)

    ``` python
    >>> from typing import Any, Tuple, TypeVar
    >>> from numerary.types import SupportsRealImag, real, imag
    >>> MyRealImagT = TypeVar("MyRealImagT", bound=SupportsRealImag)

    >>> def real_imag_my_thing(arg: MyRealImagT) -> Tuple[Any, Any]:
    ...   assert isinstance(arg, SupportsRealImag)
    ...   return (real(arg), imag(arg))

    >>> real_imag_my_thing(3)
    (3, 0)

    >>> from decimal import Decimal
    >>> real_imag_my_thing(Decimal(2.5))
    (Decimal('2.5'), Decimal('0'))

    >>> # error: Value of type variable "MyRealImagT" of "real_imag_my_thing" cannot be "str"
    >>> real_imag_my_thing("not-a-number")  # type: ignore [type-var]
    Traceback (most recent call last):
      ...
    AssertionError

    ```
    """

SupportsRealImagAsMethod

Bases: _SupportsRealImagAsMethod, Protocol

A caching ABC defining the as_real_imag method that returns a 2-tuple.

(_SupportsRealImagAsMethod is the raw, non-caching version that defines the actual methods.)

See also the real and imag helper functions.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
>>> from typing import Any, Tuple, TypeVar
>>> from numerary.types import SupportsRealImagAsMethod, real, imag
>>> MyRealImagAsMethodT = TypeVar("MyRealImagAsMethodT", bound=SupportsRealImagAsMethod)

>>> def as_real_imag_my_thing(arg: MyRealImagAsMethodT) -> Tuple[Any, Any]:
...   assert isinstance(arg, SupportsRealImagAsMethod)
...   return (real(arg), imag(arg))

>>> as_real_imag_my_thing(sympy.Float(3.5))
(3.5, 0)
>>> tuple(type(i) for i in _)
(<class 'sympy.core.numbers.Float'>, <class 'sympy.core.numbers.Zero'>)

>>> # error: Value of type variable "MyRealImagAsMethodT" of "as_real_imag_my_thing" cannot be "str"
>>> as_real_imag_my_thing("not-a-number")  # type: ignore [type-var]
Traceback (most recent call last):
  ...
AssertionError
Source code in numerary/types.py
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
@runtime_checkable
class SupportsRealImagAsMethod(
    _SupportsRealImagAsMethod,
    Protocol,
    metaclass=CachingProtocolMeta,
):
    r"""
    A caching ABC defining the ``#!python as_real_imag`` method that returns a 2-tuple.

    ([``_SupportsRealImagAsMethod``][numerary.types._SupportsRealImagAsMethod]
    is the raw, non-caching version that defines the actual methods.)

    See also the [``real``][numerary.types.real] and [``imag``][numerary.types.imag]
    helper functions.

    ``` python
    >>> from typing import Any, Tuple, TypeVar
    >>> from numerary.types import SupportsRealImagAsMethod, real, imag
    >>> MyRealImagAsMethodT = TypeVar("MyRealImagAsMethodT", bound=SupportsRealImagAsMethod)

    >>> def as_real_imag_my_thing(arg: MyRealImagAsMethodT) -> Tuple[Any, Any]:
    ...   assert isinstance(arg, SupportsRealImagAsMethod)
    ...   return (real(arg), imag(arg))

    >>> as_real_imag_my_thing(sympy.Float(3.5))
    (3.5, 0)
    >>> tuple(type(i) for i in _)
    (<class 'sympy.core.numbers.Float'>, <class 'sympy.core.numbers.Zero'>)

    >>> # error: Value of type variable "MyRealImagAsMethodT" of "as_real_imag_my_thing" cannot be "str"
    >>> as_real_imag_my_thing("not-a-number")  # type: ignore [type-var]
    Traceback (most recent call last):
      ...
    AssertionError

    ```
    """

SupportsTrunc

Bases: _SupportsTrunc, Protocol

A caching ABC defining the __trunc__ method.

See also the __trunc__ helper function.

(_SupportsTrunc is the raw, non-caching version that defines the actual methods.)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
>>> from typing import Any, Tuple, TypeVar
>>> from numerary.types import SupportsTrunc, __trunc__
>>> MyTruncT = TypeVar("MyTruncT", bound=SupportsTrunc)

>>> def trunc_my_thing(arg: MyTruncT) -> Tuple[Any, Any]:
...   assert isinstance(arg, SupportsTrunc)
...   return __trunc__(arg)

>>> trunc_my_thing(3)
3

>>> from decimal import Decimal
>>> trunc_my_thing(Decimal(2.5))
2

>>> import sympy
>>> trunc_my_thing(sympy.Float(3.5))
3
>>> type(_)
<class 'sympy.core.numbers.Integer'>

>>> # error: Value of type variable "MyTruncT" of "trunc_my_thing" cannot be "str"
>>> trunc_my_thing("not-a-number")  # type: ignore [type-var]
Traceback (most recent call last):
  ...
AssertionError
Source code in numerary/types.py
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
@runtime_checkable
class SupportsTrunc(
    _SupportsTrunc,
    Protocol,
    metaclass=CachingProtocolMeta,
):
    r"""
    A caching ABC defining the [``__trunc__``
    method](https://docs.python.org/3/reference/datamodel.html#object.__trunc__).

    See also the [``__trunc__`` helper function][numerary.types.__trunc__].

    ([``_SupportsTrunc``][numerary.types._SupportsTrunc] is the raw, non-caching version
    that defines the actual methods.)

    ``` python
    >>> from typing import Any, Tuple, TypeVar
    >>> from numerary.types import SupportsTrunc, __trunc__
    >>> MyTruncT = TypeVar("MyTruncT", bound=SupportsTrunc)

    >>> def trunc_my_thing(arg: MyTruncT) -> Tuple[Any, Any]:
    ...   assert isinstance(arg, SupportsTrunc)
    ...   return __trunc__(arg)

    >>> trunc_my_thing(3)
    3

    >>> from decimal import Decimal
    >>> trunc_my_thing(Decimal(2.5))
    2

    >>> import sympy
    >>> trunc_my_thing(sympy.Float(3.5))
    3
    >>> type(_)
    <class 'sympy.core.numbers.Integer'>

    >>> # error: Value of type variable "MyTruncT" of "trunc_my_thing" cannot be "str"
    >>> trunc_my_thing("not-a-number")  # type: ignore [type-var]
    Traceback (most recent call last):
      ...
    AssertionError

    ```
    """

SupportsFloorCeil

Bases: _SupportsFloorCeil, Protocol

A caching ABC defining the __floor__. and __ceil__ methods.

(_SupportsFloorCeil is the raw, non-caching version that defines the actual methods.)

Note

This is of limited value for Python versions prior to 3.9, since float.__floor__ and float.__ceil__ were not defined. If support for those environments is important, consider using SupportsFloat instead.

See also the __floor__ and __ceil__ helper functions.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
>>> from typing import Any, Tuple, TypeVar
>>> from numerary.types import SupportsFloorCeil, __ceil__, __floor__
>>> MyFloorCeilT = TypeVar("MyFloorCeilT", bound=SupportsFloorCeil)

>>> def floor_ceil_my_thing(arg: MyFloorCeilT) -> Tuple[int, int]:
...   assert isinstance(arg, SupportsFloorCeil)
...   return __floor__(arg), __ceil__(arg)

>>> floor_ceil_my_thing(3)
(3, 3)

>>> from decimal import Decimal
>>> floor_ceil_my_thing(Decimal(2.5))
(2, 3)

>>> import sympy
>>> floor_ceil_my_thing(sympy.Float(3.5))
(3, 4)
>>> tuple(type(i) for i in _)
(<class 'sympy.core.numbers.Integer'>, <class 'sympy.core.numbers.Integer'>)

>>> # error: Value of type variable "MyFloorCeilT" of "floor_ceil_my_thing" cannot be "str"
>>> floor_ceil_my_thing("not-a-number")  # type: ignore [type-var]
Traceback (most recent call last):
  ...
AssertionError
Source code in numerary/types.py
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
@runtime_checkable
class SupportsFloorCeil(
    _SupportsFloorCeil,
    Protocol,
    metaclass=CachingProtocolMeta,
):
    r"""
    A caching ABC defining the
    [``__floor__``](https://docs.python.org/3/reference/datamodel.html#object.__floor__).
    and
    [``__ceil__``](https://docs.python.org/3/reference/datamodel.html#object.__ceil__)
    methods.

    ([``_SupportsFloorCeil``][numerary.types._SupportsFloorCeil] is the raw, non-caching
    version that defines the actual methods.)

    !!! note

        This is of limited value for Python versions prior to 3.9, since ``#!python
        float.__floor__`` and ``#!python float.__ceil__`` were not defined. If support
        for those environments is important, consider using
        [``SupportsFloat``][numerary.types.SupportsFloat] instead.

        See also the [``__floor__``][numerary.types.__floor__] and
        [``__ceil__``][numerary.types.__ceil__] helper functions.

    ``` python
    >>> from typing import Any, Tuple, TypeVar
    >>> from numerary.types import SupportsFloorCeil, __ceil__, __floor__
    >>> MyFloorCeilT = TypeVar("MyFloorCeilT", bound=SupportsFloorCeil)

    >>> def floor_ceil_my_thing(arg: MyFloorCeilT) -> Tuple[int, int]:
    ...   assert isinstance(arg, SupportsFloorCeil)
    ...   return __floor__(arg), __ceil__(arg)

    >>> floor_ceil_my_thing(3)
    (3, 3)

    >>> from decimal import Decimal
    >>> floor_ceil_my_thing(Decimal(2.5))
    (2, 3)

    >>> import sympy
    >>> floor_ceil_my_thing(sympy.Float(3.5))
    (3, 4)
    >>> tuple(type(i) for i in _)
    (<class 'sympy.core.numbers.Integer'>, <class 'sympy.core.numbers.Integer'>)

    >>> # error: Value of type variable "MyFloorCeilT" of "floor_ceil_my_thing" cannot be "str"
    >>> floor_ceil_my_thing("not-a-number")  # type: ignore [type-var]
    Traceback (most recent call last):
      ...
    AssertionError

    ```
    """

SupportsDivmod

Bases: _SupportsDivmod[_T_co], Protocol, Generic[_T_co]

A caching ABC defining the __divmod__ and __rdivmod__ methods. Each returns a 2-tuple of covariants.

(_SupportsDivmod is the raw, non-caching version that defines the actual methods.)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
>>> from typing import Any, Tuple, TypeVar
>>> from numerary.types import SupportsDivmod
>>> MyDivmodT = TypeVar("MyDivmodT", bound=SupportsDivmod)

>>> def divmod_my_thing(arg: MyDivmodT, other: Any) -> Tuple[MyDivmodT, MyDivmodT]:
...   assert isinstance(arg, SupportsDivmod)
...   return divmod(arg, other)

>>> divmod_my_thing(2, 1)
(2, 0)

>>> from decimal import Decimal
>>> divmod_my_thing(Decimal(2.5), Decimal(1.5))
(Decimal('1'), Decimal('1.0'))

>>> import sympy
>>> divmod_my_thing(sympy.Float(3.5), sympy.Float(1.5))
(2, 0.5)
>>> tuple(type(i) for i in _)
(<class 'sympy.core.numbers.Integer'>, <class 'sympy.core.numbers.Float'>)

>>> # error: Value of type variable "MyDivmodT" of "divmod_my_thing" cannot be "str"
>>> divmod_my_thing("not-a-number", "still-not-a-number")  # type: ignore [type-var]
Traceback (most recent call last):
  ...
AssertionError
Source code in numerary/types.py
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
@runtime_checkable
class SupportsDivmod(
    _SupportsDivmod[_T_co],
    Protocol,
    Generic[_T_co],
    metaclass=CachingProtocolMeta,
):
    r"""
    A caching ABC defining the
    [``__divmod__``](https://docs.python.org/3/reference/datamodel.html#object.__divmod__)
    and
    [``__rdivmod__``](https://docs.python.org/3/reference/datamodel.html#object.__rdivmod__)
    methods. Each returns a 2-tuple of covariants.

    ([``_SupportsDivmod``][numerary.types._SupportsDivmod] is the raw, non-caching
    version that defines the actual methods.)

    ``` python
    >>> from typing import Any, Tuple, TypeVar
    >>> from numerary.types import SupportsDivmod
    >>> MyDivmodT = TypeVar("MyDivmodT", bound=SupportsDivmod)

    >>> def divmod_my_thing(arg: MyDivmodT, other: Any) -> Tuple[MyDivmodT, MyDivmodT]:
    ...   assert isinstance(arg, SupportsDivmod)
    ...   return divmod(arg, other)

    >>> divmod_my_thing(2, 1)
    (2, 0)

    >>> from decimal import Decimal
    >>> divmod_my_thing(Decimal(2.5), Decimal(1.5))
    (Decimal('1'), Decimal('1.0'))

    >>> import sympy
    >>> divmod_my_thing(sympy.Float(3.5), sympy.Float(1.5))
    (2, 0.5)
    >>> tuple(type(i) for i in _)
    (<class 'sympy.core.numbers.Integer'>, <class 'sympy.core.numbers.Float'>)

    >>> # error: Value of type variable "MyDivmodT" of "divmod_my_thing" cannot be "str"
    >>> divmod_my_thing("not-a-number", "still-not-a-number")  # type: ignore [type-var]
    Traceback (most recent call last):
      ...
    AssertionError

    ```
    """

SupportsNumeratorDenominator

Bases: _SupportsNumeratorDenominator, Protocol

A caching ABC defining the numerator and denominator properties.

(_SupportsNumeratorDenominator is the raw, non-caching version that defines the actual properties.)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
>>> from typing import Any, Tuple, TypeVar
>>> from numerary.types import SupportsNumeratorDenominator, denominator, numerator
>>> MyNumDenomT = TypeVar("MyNumDenomT", bound=SupportsNumeratorDenominator)

>>> def num_denom_my_thing(arg: MyNumDenomT) -> Tuple[int, int]:
...   assert isinstance(arg, SupportsNumeratorDenominator)
...   return numerator(arg), denominator(arg)

>>> num_denom_my_thing(3)
(3, 1)

>>> from fractions import Fraction
>>> num_denom_my_thing(Fraction(2, 3))
(2, 3)

>>> import sympy
>>> num_denom_my_thing(sympy.Rational(3, 4))
(3, 4)
>>> tuple(type(i) for i in _)
(<class 'int'>, <class 'int'>)

>>> # error: Value of type variable "MyNumDenomT" of "num_denom_my_thing" cannot be "str"
>>> num_denom_my_thing("not-a-number")  # type: ignore [type-var]
Traceback (most recent call last):
  ...
AssertionError
Source code in numerary/types.py
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
@runtime_checkable
class SupportsNumeratorDenominator(
    _SupportsNumeratorDenominator,
    Protocol,
    metaclass=CachingProtocolMeta,
):
    r"""
    A caching ABC defining the
    [``numerator``](https://docs.python.org/3/library/numbers.html#numbers.Rational.numerator)
    and
    [``denominator``](https://docs.python.org/3/library/numbers.html#numbers.Rational.denominator)
    properties.

    ([``_SupportsNumeratorDenominator``][numerary.types._SupportsNumeratorDenominator]
    is the raw, non-caching version that defines the actual properties.)

    ``` python
    >>> from typing import Any, Tuple, TypeVar
    >>> from numerary.types import SupportsNumeratorDenominator, denominator, numerator
    >>> MyNumDenomT = TypeVar("MyNumDenomT", bound=SupportsNumeratorDenominator)

    >>> def num_denom_my_thing(arg: MyNumDenomT) -> Tuple[int, int]:
    ...   assert isinstance(arg, SupportsNumeratorDenominator)
    ...   return numerator(arg), denominator(arg)

    >>> num_denom_my_thing(3)
    (3, 1)

    >>> from fractions import Fraction
    >>> num_denom_my_thing(Fraction(2, 3))
    (2, 3)

    >>> import sympy
    >>> num_denom_my_thing(sympy.Rational(3, 4))
    (3, 4)
    >>> tuple(type(i) for i in _)
    (<class 'int'>, <class 'int'>)

    >>> # error: Value of type variable "MyNumDenomT" of "num_denom_my_thing" cannot be "str"
    >>> num_denom_my_thing("not-a-number")  # type: ignore [type-var]
    Traceback (most recent call last):
      ...
    AssertionError

    ```
    """

SupportsNumeratorDenominatorMethods

Bases: _SupportsNumeratorDenominatorMethods, Protocol

A caching ABC defining numerator and denominator methods. Each returns a SupportsInt.

(_SupportsNumeratorDenominatorMethods is the raw, non-caching version that defines the actual methods.)

See also the numerator and denominator helper functions.

Source code in numerary/types.py
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
@runtime_checkable
class SupportsNumeratorDenominatorMethods(
    _SupportsNumeratorDenominatorMethods,
    Protocol,
    metaclass=CachingProtocolMeta,
):
    r"""
    A caching ABC defining ``#!python numerator`` and ``#!python denominator`` methods.
    Each returns a [``SupportsInt``][numerary.types.SupportsInt].

    ([``_SupportsNumeratorDenominatorMethods``][numerary.types._SupportsNumeratorDenominatorMethods]
    is the raw, non-caching version that defines the actual methods.)

    See also the [``numerator``][numerary.types.numerator] and
    [``denominator``][numerary.types.denominator] helper functions.
    """

SupportsComplexOps

Bases: _SupportsComplexOps[_T_co], Protocol, Generic[_T_co]

A caching ABC defining the Complex operator methods with covariant return values.

(_SupportsComplexOps is the raw, non-caching version that defines the actual methods.)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
>>> from typing import Any, Tuple, TypeVar
>>> from numerary.types import SupportsComplexOps
>>> MyComplexOpsT = TypeVar("MyComplexOpsT", bound=SupportsComplexOps)

>>> def complex_ops_my_thing(arg: MyComplexOpsT) -> MyComplexOpsT:
...   assert isinstance(arg, SupportsComplexOps)
...   return arg * -2 + 5

>>> complex_ops_my_thing(3)
-1

>>> from decimal import Decimal
>>> complex_ops_my_thing(Decimal("2.5"))
Decimal('0.0')

>>> import sympy
>>> complex_ops_my_thing(sympy.Float(3.5))
-2.0
>>> type(_)
<class 'sympy.core.numbers.Float'>

>>> # error: Value of type variable "MyComplexOpsT" of "complex_ops_my_thing" cannot be "str"
>>> complex_ops_my_thing("not-a-number")  # type: ignore [type-var]
Traceback (most recent call last):
  ...
AssertionError
Source code in numerary/types.py
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
@runtime_checkable
class SupportsComplexOps(
    _SupportsComplexOps[_T_co],
    Protocol,
    Generic[_T_co],
    metaclass=CachingProtocolMeta,
):
    r"""
    A caching ABC defining the [``Complex`` operator
    methods](https://docs.python.org/3/library/numbers.html#numbers.Complex) with
    covariant return values.

    ([``_SupportsComplexOps``][numerary.types._SupportsComplexOps] is the raw,
    non-caching version that defines the actual methods.)

    ``` python
    >>> from typing import Any, Tuple, TypeVar
    >>> from numerary.types import SupportsComplexOps
    >>> MyComplexOpsT = TypeVar("MyComplexOpsT", bound=SupportsComplexOps)

    >>> def complex_ops_my_thing(arg: MyComplexOpsT) -> MyComplexOpsT:
    ...   assert isinstance(arg, SupportsComplexOps)
    ...   return arg * -2 + 5

    >>> complex_ops_my_thing(3)
    -1

    >>> from decimal import Decimal
    >>> complex_ops_my_thing(Decimal("2.5"))
    Decimal('0.0')

    >>> import sympy
    >>> complex_ops_my_thing(sympy.Float(3.5))
    -2.0
    >>> type(_)
    <class 'sympy.core.numbers.Float'>

    >>> # error: Value of type variable "MyComplexOpsT" of "complex_ops_my_thing" cannot be "str"
    >>> complex_ops_my_thing("not-a-number")  # type: ignore [type-var]
    Traceback (most recent call last):
      ...
    AssertionError

    ```
    """

SupportsComplexPow

Bases: _SupportsComplexPow, Protocol

A caching ABC defining the Complex (i.e., non-modulo) versions of the __pow__ and __rpow__.

(_SupportsComplexPow is the raw, non-caching version that defines the actual methods.)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
>>> from typing import Any, Tuple, TypeVar
>>> from numerary.types import SupportsComplexPow
>>> MyComplexPowT = TypeVar("MyComplexPowT", bound=SupportsComplexPow)

>>> def complex_pow_my_thing(arg: MyComplexPowT) -> MyComplexPowT:
...   assert isinstance(arg, SupportsComplexPow)
...   return arg ** -2

>>> complex_pow_my_thing(3)
0.1111111111111111

>>> from decimal import Decimal
>>> complex_pow_my_thing(Decimal("2.5"))
Decimal('0.16')

>>> import sympy
>>> complex_pow_my_thing(sympy.Float(3.5))
0.0816326530612245
>>> type(_)
<class 'sympy.core.numbers.Float'>

>>> # error: Value of type variable "MyComplexPowT" of "complex_pow_my_thing" cannot be "str"
>>> complex_pow_my_thing("not-a-number")  # type: ignore [type-var]
Traceback (most recent call last):
  ...
AssertionError
Source code in numerary/types.py
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
@runtime_checkable
class SupportsComplexPow(
    _SupportsComplexPow,
    Protocol,
    metaclass=CachingProtocolMeta,
):
    r"""
    A caching ABC defining the ``#!python Complex`` (i.e., non-modulo) versions of the
    [``__pow__``](https://docs.python.org/3/reference/datamodel.html#object.__pow__) and
    [``__rpow__``](https://docs.python.org/3/reference/datamodel.html#object.__rpow__).

    ([``_SupportsComplexPow``][numerary.types._SupportsComplexPow] is the raw,
    non-caching version that defines the actual methods.)

    ``` python
    >>> from typing import Any, Tuple, TypeVar
    >>> from numerary.types import SupportsComplexPow
    >>> MyComplexPowT = TypeVar("MyComplexPowT", bound=SupportsComplexPow)

    >>> def complex_pow_my_thing(arg: MyComplexPowT) -> MyComplexPowT:
    ...   assert isinstance(arg, SupportsComplexPow)
    ...   return arg ** -2

    >>> complex_pow_my_thing(3)
    0.1111111111111111

    >>> from decimal import Decimal
    >>> complex_pow_my_thing(Decimal("2.5"))
    Decimal('0.16')

    >>> import sympy
    >>> complex_pow_my_thing(sympy.Float(3.5))
    0.0816326530612245
    >>> type(_)
    <class 'sympy.core.numbers.Float'>

    >>> # error: Value of type variable "MyComplexPowT" of "complex_pow_my_thing" cannot be "str"
    >>> complex_pow_my_thing("not-a-number")  # type: ignore [type-var]
    Traceback (most recent call last):
      ...
    AssertionError

    ```
    """

SupportsRealOps

Bases: _SupportsRealOps[_T_co], Protocol, Generic[_T_co]

A caching ABC defining the Real operator methods with covariant return values.

(_SupportsRealOps is the raw, non-caching version that defines the actual methods.)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
>>> from typing import Any, Tuple, TypeVar
>>> from numerary.types import SupportsRealOps
>>> MyRealOpsT = TypeVar("MyRealOpsT", bound=SupportsRealOps)

>>> def real_ops_my_thing(arg: MyRealOpsT) -> Any:
...   assert isinstance(arg, SupportsRealOps)
...   return arg // -2

>>> real_ops_my_thing(3)
-2

>>> from decimal import Decimal
>>> real_ops_my_thing(Decimal("2.5"))
Decimal('-1')

>>> import sympy
>>> real_ops_my_thing(sympy.Float(3.5))
-2
>>> type(_)
<class 'sympy.core.numbers.Integer'>

>>> # error: Value of type variable "MyRealOpsT" of "real_ops_my_thing" cannot be "str"
>>> real_ops_my_thing("not-a-number")  # type: ignore [type-var]
Traceback (most recent call last):
  ...
AssertionError
Source code in numerary/types.py
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
@runtime_checkable
class SupportsRealOps(
    _SupportsRealOps[_T_co],
    Protocol,
    Generic[_T_co],
    metaclass=CachingProtocolMeta,
):
    r"""
    A caching ABC defining the [``Real`` operator
    methods](https://docs.python.org/3/library/numbers.html#numbers.Real) with covariant
    return values.

    ([``_SupportsRealOps``][numerary.types._SupportsRealOps] is the raw, non-caching
    version that defines the actual methods.)

    ``` python
    >>> from typing import Any, Tuple, TypeVar
    >>> from numerary.types import SupportsRealOps
    >>> MyRealOpsT = TypeVar("MyRealOpsT", bound=SupportsRealOps)

    >>> def real_ops_my_thing(arg: MyRealOpsT) -> Any:
    ...   assert isinstance(arg, SupportsRealOps)
    ...   return arg // -2

    >>> real_ops_my_thing(3)
    -2

    >>> from decimal import Decimal
    >>> real_ops_my_thing(Decimal("2.5"))
    Decimal('-1')

    >>> import sympy
    >>> real_ops_my_thing(sympy.Float(3.5))
    -2
    >>> type(_)
    <class 'sympy.core.numbers.Integer'>

    >>> # error: Value of type variable "MyRealOpsT" of "real_ops_my_thing" cannot be "str"
    >>> real_ops_my_thing("not-a-number")  # type: ignore [type-var]
    Traceback (most recent call last):
      ...
    AssertionError

    ```
    """

SupportsIntegralOps

Bases: _SupportsIntegralOps[_T_co], Protocol, Generic[_T_co]

A caching ABC defining the Integral operator methods with covariant return values.

(_SupportsIntegralOps is the raw, non-caching version that defines the actual methods.)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
>>> from typing import Any, Tuple, TypeVar
>>> from numerary.types import SupportsIntegralOps
>>> MyIntegralOpsT = TypeVar("MyIntegralOpsT", bound=SupportsIntegralOps)

>>> def integral_ops_my_thing(arg: MyIntegralOpsT) -> MyIntegralOpsT:
...   assert isinstance(arg, SupportsIntegralOps)
...   return arg << 1

>>> integral_ops_my_thing(3)
6

>>> import sympy
>>> integral_ops_my_thing(sympy.Integer(3))
6
>>> type(_)
<class 'sympy.core.numbers.Integer'>

>>> # error: Value of type variable "MyIntegralOpsT" of "integral_ops_my_thing" cannot be "str"
>>> integral_ops_my_thing("not-a-number")  # type: ignore [type-var]
Traceback (most recent call last):
  ...
AssertionError
Source code in numerary/types.py
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
@runtime_checkable
class SupportsIntegralOps(
    _SupportsIntegralOps[_T_co],
    Protocol,
    Generic[_T_co],
    metaclass=CachingProtocolMeta,
):
    r"""
    A caching ABC defining the [``Integral`` operator
    methods](https://docs.python.org/3/library/numbers.html#numbers.Integral) with
    covariant return values.

    ([``_SupportsIntegralOps``][numerary.types._SupportsIntegralOps] is the raw,
    non-caching version that defines the actual methods.)

    ``` python
    >>> from typing import Any, Tuple, TypeVar
    >>> from numerary.types import SupportsIntegralOps
    >>> MyIntegralOpsT = TypeVar("MyIntegralOpsT", bound=SupportsIntegralOps)

    >>> def integral_ops_my_thing(arg: MyIntegralOpsT) -> MyIntegralOpsT:
    ...   assert isinstance(arg, SupportsIntegralOps)
    ...   return arg << 1

    >>> integral_ops_my_thing(3)
    6

    >>> import sympy
    >>> integral_ops_my_thing(sympy.Integer(3))
    6
    >>> type(_)
    <class 'sympy.core.numbers.Integer'>

    >>> # error: Value of type variable "MyIntegralOpsT" of "integral_ops_my_thing" cannot be "str"
    >>> integral_ops_my_thing("not-a-number")  # type: ignore [type-var]
    Traceback (most recent call last):
      ...
    AssertionError

    ```
    """

SupportsIntegralPow

Bases: _SupportsIntegralPow, Protocol

A caching ABC defining the Integral (i.e., modulo) versions of the __pow__ and __rpow__ methods.

(_SupportsIntegralPow is the raw, non-caching version that defines the actual methods.)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
>>> from typing import Any, Tuple, TypeVar
>>> from numerary.types import SupportsIntegralPow
>>> MyIntegralPowT = TypeVar("MyIntegralPowT", bound=SupportsIntegralPow)

>>> def integral_pow_my_thing(arg: MyIntegralPowT) -> MyIntegralPowT:
...   assert isinstance(arg, SupportsIntegralPow)
...   return pow(arg, 2, 2)

>>> integral_pow_my_thing(3)
1

>>> import sympy
>>> integral_pow_my_thing(sympy.Integer(3))
1
>>> type(_)
<class 'sympy.core.numbers.One'>

>>> # error: Value of type variable "MyIntegralPowT" of "integral_pow_my_thing" cannot be "str"
>>> integral_pow_my_thing("not-a-number")  # type: ignore [type-var]
Traceback (most recent call last):
  ...
AssertionError
Source code in numerary/types.py
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
@runtime_checkable
class SupportsIntegralPow(
    _SupportsIntegralPow,
    Protocol,
    metaclass=CachingProtocolMeta,
):
    r"""
    A caching ABC defining the ``#!python Integral`` (i.e., modulo) versions of the
    [``__pow__``](https://docs.python.org/3/reference/datamodel.html#object.__pow__) and
    [``__rpow__``](https://docs.python.org/3/reference/datamodel.html#object.__rpow__)
    methods.

    ([``_SupportsIntegralPow``][numerary.types._SupportsIntegralPow] is the raw,
    non-caching version that defines the actual methods.)

    ``` python
    >>> from typing import Any, Tuple, TypeVar
    >>> from numerary.types import SupportsIntegralPow
    >>> MyIntegralPowT = TypeVar("MyIntegralPowT", bound=SupportsIntegralPow)

    >>> def integral_pow_my_thing(arg: MyIntegralPowT) -> MyIntegralPowT:
    ...   assert isinstance(arg, SupportsIntegralPow)
    ...   return pow(arg, 2, 2)

    >>> integral_pow_my_thing(3)
    1

    >>> import sympy
    >>> integral_pow_my_thing(sympy.Integer(3))
    1
    >>> type(_)
    <class 'sympy.core.numbers.One'>

    >>> # error: Value of type variable "MyIntegralPowT" of "integral_pow_my_thing" cannot be "str"
    >>> integral_pow_my_thing("not-a-number")  # type: ignore [type-var]
    Traceback (most recent call last):
      ...
    AssertionError

    ```
    """

real(operand: SupportsRealImagMixedU)

Helper function that extracts the real part from operand including resolving non-compliant implementations that implement such extraction via a as_real_imag method rather than as properties.

1
2
3
4
>>> import sympy
>>> from numerary.types import real
>>> real(sympy.Float(3.5))
3.5

See SupportsRealImag and SupportsRealImagAsMethod.

Source code in numerary/types.py
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
@beartype
def real(operand: SupportsRealImagMixedU):
    r"""
    Helper function that extracts the real part from *operand* including resolving
    non-compliant implementations that implement such extraction via a ``as_real_imag``
    method rather than as properties.

    ``` python
    >>> import sympy
    >>> from numerary.types import real
    >>> real(sympy.Float(3.5))
    3.5

    ```

    See
    [SupportsRealImag][numerary.types.SupportsRealImag]
    and
    [SupportsRealImagAsMethod][numerary.types.SupportsRealImagAsMethod].
    """
    if callable(getattr(operand, "as_real_imag", None)):
        real_part, _ = operand.as_real_imag()  # type: ignore [union-attr]

        return real_part
    elif hasattr(operand, "real"):
        return operand.real
    else:
        raise TypeError(f"{operand!r} has no real or as_real_imag")

imag(operand: SupportsRealImagMixedU)

Helper function that extracts the imaginary part from operand including resolving non-compliant implementations that implement such extraction via a as_real_imag method rather than as properties.

1
2
3
4
>>> import sympy
>>> from numerary.types import real
>>> imag(sympy.Float(3.5))
0

See SupportsRealImag and SupportsRealImagAsMethod.

Source code in numerary/types.py
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
@beartype
def imag(operand: SupportsRealImagMixedU):
    r"""
    Helper function that extracts the imaginary part from *operand* including resolving
    non-compliant implementations that implement such extraction via a ``as_real_imag``
    method rather than as properties.

    ``` python
    >>> import sympy
    >>> from numerary.types import real
    >>> imag(sympy.Float(3.5))
    0

    ```

    See
    [SupportsRealImag][numerary.types.SupportsRealImag]
    and
    [SupportsRealImagAsMethod][numerary.types.SupportsRealImagAsMethod].
    """
    if callable(getattr(operand, "as_real_imag", None)):
        _, imag_part = operand.as_real_imag()  # type: ignore [union-attr]

        return imag_part
    elif hasattr(operand, "imag"):
        return operand.imag
    else:
        raise TypeError(f"{operand!r} has no real or as_real_imag")

__pow__(arg: Union[SupportsComplexPow, SupportsIntegralPow], exponent: Any, modulus: Optional[Any] = None) -> Any

Helper function that wraps pow to work with SupportsComplexPow, SupportsIntegralPow.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
>>> from numerary.types import SupportsComplexPow, SupportsIntegralPow, __pow__
>>> my_complex_pow: SupportsComplexPow = complex(2)
>>> __pow__(my_complex_pow, 1)
(2+0j)
>>> __pow__(my_complex_pow, 1, None)
(2+0j)
>>> __pow__(my_complex_pow, 1, 1)  # type: ignore [operator]  # properly caught by Mypy
Traceback (most recent call last):
  ...
ValueError: complex modulo

>>> my_complex_pow = 1.2
>>> __pow__(my_complex_pow, 1)
1.2
>>> __pow__(my_complex_pow, 1, None)
1.2
>>> __pow__(my_complex_pow, 1, 1)  # ugh; *not* caught by Mypy because it treats floats as equivalent to ints?
Traceback (most recent call last):
  ...
TypeError: pow() 3rd argument not allowed unless all arguments are integers
>>> from fractions import Fraction

>>> my_complex_pow = Fraction(1, 2)
>>> __pow__(my_complex_pow, 1)
Fraction(1, 2)
>>> __pow__(my_complex_pow, 1, None)
Fraction(1, 2)
>>> __pow__(my_complex_pow, 1, 1)  # type: ignore [operator]  # properly caught by Mypy
Traceback (most recent call last):
  ...
TypeError: __pow__() takes 2 positional arguments but 3 were given

>>> from decimal import Decimal
>>> my_integral_pow: SupportsIntegralPow = Decimal("2")
>>> __pow__(my_integral_pow, 1)
Decimal('2')
>>> __pow__(my_integral_pow, 1, None)
Decimal('2')
>>> __pow__(my_integral_pow, 1, 2)
Decimal('0')

>>> my_integral_pow = Decimal("1.2")  # ruh-roh
>>> __pow__(my_integral_pow, 1)
Decimal('1.2')
>>> __pow__(my_integral_pow, 1, None)
Decimal('1.2')
>>> __pow__(my_integral_pow, 1, 2)  # not catchable by Mypy, since it works *some* of the time
Traceback (most recent call last):
  ...
decimal.InvalidOperation: [<class 'decimal.InvalidOperation'>]

>>> my_integral_pow = 2
>>> __pow__(my_integral_pow, 1)
2
>>> __pow__(my_integral_pow, 1, None)
2
>>> __pow__(my_integral_pow, 1, 2)
0
Source code in numerary/types.py
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
@beartype
def __pow__(
    arg: Union[SupportsComplexPow, SupportsIntegralPow],
    exponent: Any,
    modulus: Optional[Any] = None,
) -> Any:
    r"""
    Helper function that wraps ``pow`` to work with
    [``SupportsComplexPow``][numerary.types.SupportsComplexPow],
    [``SupportsIntegralPow``][numerary.types.SupportsIntegralPow].

    ``` python
    >>> from numerary.types import SupportsComplexPow, SupportsIntegralPow, __pow__
    >>> my_complex_pow: SupportsComplexPow = complex(2)
    >>> __pow__(my_complex_pow, 1)
    (2+0j)
    >>> __pow__(my_complex_pow, 1, None)
    (2+0j)
    >>> __pow__(my_complex_pow, 1, 1)  # type: ignore [operator]  # properly caught by Mypy
    Traceback (most recent call last):
      ...
    ValueError: complex modulo

    >>> my_complex_pow = 1.2
    >>> __pow__(my_complex_pow, 1)
    1.2
    >>> __pow__(my_complex_pow, 1, None)
    1.2
    >>> __pow__(my_complex_pow, 1, 1)  # ugh; *not* caught by Mypy because it treats floats as equivalent to ints?
    Traceback (most recent call last):
      ...
    TypeError: pow() 3rd argument not allowed unless all arguments are integers
    >>> from fractions import Fraction

    >>> my_complex_pow = Fraction(1, 2)
    >>> __pow__(my_complex_pow, 1)
    Fraction(1, 2)
    >>> __pow__(my_complex_pow, 1, None)
    Fraction(1, 2)
    >>> __pow__(my_complex_pow, 1, 1)  # type: ignore [operator]  # properly caught by Mypy
    Traceback (most recent call last):
      ...
    TypeError: __pow__() takes 2 positional arguments but 3 were given

    >>> from decimal import Decimal
    >>> my_integral_pow: SupportsIntegralPow = Decimal("2")
    >>> __pow__(my_integral_pow, 1)
    Decimal('2')
    >>> __pow__(my_integral_pow, 1, None)
    Decimal('2')
    >>> __pow__(my_integral_pow, 1, 2)
    Decimal('0')

    >>> my_integral_pow = Decimal("1.2")  # ruh-roh
    >>> __pow__(my_integral_pow, 1)
    Decimal('1.2')
    >>> __pow__(my_integral_pow, 1, None)
    Decimal('1.2')
    >>> __pow__(my_integral_pow, 1, 2)  # not catchable by Mypy, since it works *some* of the time
    Traceback (most recent call last):
      ...
    decimal.InvalidOperation: [<class 'decimal.InvalidOperation'>]

    >>> my_integral_pow = 2
    >>> __pow__(my_integral_pow, 1)
    2
    >>> __pow__(my_integral_pow, 1, None)
    2
    >>> __pow__(my_integral_pow, 1, 2)
    0

    ```
    """
    return pow(arg, exponent, modulus)

__trunc__(operand: Union[SupportsFloat, SupportsTrunc])

Helper function that wraps math.trunc.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
>>> from numerary.types import SupportsFloat, SupportsTrunc, __trunc__
>>> my_trunc: SupportsTrunc
>>> my_trunc = 1
>>> __trunc__(my_trunc)
1
>>> from fractions import Fraction
>>> my_trunc = Fraction(1, 2)
>>> __trunc__(my_trunc)
0
>>> my_trunc_float: SupportsFloat = 1.2
>>> __trunc__(my_trunc_float)
1
Source code in numerary/types.py
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
@beartype
def __trunc__(operand: Union[SupportsFloat, SupportsTrunc]):
    r"""
    Helper function that wraps ``math.trunc``.

    ``` python
    >>> from numerary.types import SupportsFloat, SupportsTrunc, __trunc__
    >>> my_trunc: SupportsTrunc
    >>> my_trunc = 1
    >>> __trunc__(my_trunc)
    1
    >>> from fractions import Fraction
    >>> my_trunc = Fraction(1, 2)
    >>> __trunc__(my_trunc)
    0
    >>> my_trunc_float: SupportsFloat = 1.2
    >>> __trunc__(my_trunc_float)
    1

    ```
    """
    return math.trunc(operand)  # type: ignore [arg-type]

__floor__(operand: Union[SupportsFloat, SupportsFloorCeil])

Helper function that wraps math.floor.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
>>> from numerary.types import SupportsFloat, SupportsFloorCeil, __floor__
>>> my_floor: SupportsFloorCeil
>>> my_floor = 1
>>> __floor__(my_floor)
1
>>> from fractions import Fraction
>>> my_floor = Fraction(1, 2)
>>> __floor__(my_floor)
0
>>> my_floor_float: SupportsFloat = 1.2
>>> __floor__(my_floor_float)
1
Source code in numerary/types.py
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
@beartype
def __floor__(operand: Union[SupportsFloat, SupportsFloorCeil]):
    r"""
    Helper function that wraps ``math.floor``.

    ``` python
    >>> from numerary.types import SupportsFloat, SupportsFloorCeil, __floor__
    >>> my_floor: SupportsFloorCeil
    >>> my_floor = 1
    >>> __floor__(my_floor)
    1
    >>> from fractions import Fraction
    >>> my_floor = Fraction(1, 2)
    >>> __floor__(my_floor)
    0
    >>> my_floor_float: SupportsFloat = 1.2
    >>> __floor__(my_floor_float)
    1

    ```
    """
    return math.floor(operand)

__ceil__(operand: Union[SupportsFloat, SupportsFloorCeil])

Helper function that wraps math.ceil.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
>>> from numerary.types import SupportsFloat, SupportsFloorCeil, __ceil__
>>> my_ceil: SupportsFloorCeil
>>> my_ceil = 1
>>> __ceil__(my_ceil)
1
>>> from fractions import Fraction
>>> my_ceil = Fraction(1, 2)
>>> __ceil__(my_ceil)
1
>>> my_ceil_float: SupportsFloat = 1.2
>>> __ceil__(my_ceil_float)
2
Source code in numerary/types.py
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
@beartype
def __ceil__(operand: Union[SupportsFloat, SupportsFloorCeil]):
    r"""
    Helper function that wraps ``math.ceil``.

    ``` python
    >>> from numerary.types import SupportsFloat, SupportsFloorCeil, __ceil__
    >>> my_ceil: SupportsFloorCeil
    >>> my_ceil = 1
    >>> __ceil__(my_ceil)
    1
    >>> from fractions import Fraction
    >>> my_ceil = Fraction(1, 2)
    >>> __ceil__(my_ceil)
    1
    >>> my_ceil_float: SupportsFloat = 1.2
    >>> __ceil__(my_ceil_float)
    2

    ```
    """
    return math.ceil(operand)

numerator(operand: SupportsNumeratorDenominatorMixedU)

Helper function that extracts the numerator from operand including resolving non-compliant rational implementations that implement numerator as a method rather than a property.

1
2
3
4
>>> from fractions import Fraction
>>> from numerary.types import numerator
>>> numerator(Fraction(22, 7))
22

See SupportsNumeratorDenominator and SupportsNumeratorDenominatorMethods.

Source code in numerary/types.py
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
@beartype
def numerator(operand: SupportsNumeratorDenominatorMixedU):
    r"""
    Helper function that extracts the numerator from *operand* including resolving
    non-compliant rational implementations that implement ``numerator`` as a method
    rather than a property.

    ``` python
    >>> from fractions import Fraction
    >>> from numerary.types import numerator
    >>> numerator(Fraction(22, 7))
    22

    ```

    See
    [SupportsNumeratorDenominator][numerary.types.SupportsNumeratorDenominator]
    and
    [SupportsNumeratorDenominatorMethods][numerary.types.SupportsNumeratorDenominatorMethods].
    """
    if hasattr(operand, "numerator"):
        if callable(operand.numerator):
            return operand.numerator()
        else:
            return operand.numerator
    else:
        raise TypeError(f"{operand!r} has no numerator")

denominator(operand: SupportsNumeratorDenominatorMixedU)

Helper function that extracts the denominator from operand including resolving non-compliant rational implementations that implement denominator as a method rather than a property.

1
2
3
4
>>> from fractions import Fraction
>>> from numerary.types import denominator
>>> denominator(Fraction(22, 7))
7

See SupportsNumeratorDenominator and SupportsNumeratorDenominatorMethods.

Source code in numerary/types.py
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
@beartype
def denominator(operand: SupportsNumeratorDenominatorMixedU):
    r"""
    Helper function that extracts the denominator from *operand* including resolving
    non-compliant rational implementations that implement ``denominator`` as a method
    rather than a property.

    ``` python
    >>> from fractions import Fraction
    >>> from numerary.types import denominator
    >>> denominator(Fraction(22, 7))
    7

    ```

    See
    [SupportsNumeratorDenominator][numerary.types.SupportsNumeratorDenominator]
    and
    [SupportsNumeratorDenominatorMethods][numerary.types.SupportsNumeratorDenominatorMethods].
    """
    if hasattr(operand, "denominator"):
        if callable(operand.denominator):
            return operand.denominator()
        else:
            return operand.denominator
    else:
        raise TypeError(f"{operand!r} has no denominator")

RationalLikeMixedT = (RationalLike, RationalLikeMethods) module-attribute

RationalLikeMixedU = Union[RationalLike, RationalLikeMethods] module-attribute

SupportsRealImagMixedT = (SupportsRealImag, SupportsRealImagAsMethod) module-attribute

SupportsRealImagMixedU = Union[SupportsRealImag, SupportsRealImagAsMethod] module-attribute

SupportsNumeratorDenominatorMixedT = (SupportsNumeratorDenominator, SupportsNumeratorDenominatorMethods) module-attribute

SupportsNumeratorDenominatorMixedU = Union[SupportsNumeratorDenominator, SupportsNumeratorDenominatorMethods] module-attribute

_SupportsConjugate

Bases: _Protocol

The non-caching version of SupportsConjugate.

Source code in numerary/types.py
153
154
155
156
157
158
159
160
161
162
@runtime_checkable
class _SupportsConjugate(_Protocol):
    r"""
    The non-caching version of
    [``SupportsConjugate``][numerary.types.SupportsConjugate].
    """

    @abstractmethod
    def conjugate(self) -> Any:
        pass

conjugate() -> Any abstractmethod

Source code in numerary/types.py
160
161
162
@abstractmethod
def conjugate(self) -> Any:
    pass

_SupportsRealImag

Bases: _Protocol

The non-caching version of SupportsRealImag.

Source code in numerary/types.py
215
216
217
218
219
220
221
222
223
224
225
226
227
@runtime_checkable
class _SupportsRealImag(_Protocol):
    r"""
    The non-caching version of [``SupportsRealImag``][numerary.types.SupportsRealImag].
    """

    @abstractproperty
    def real(self) -> Any:
        pass

    @abstractproperty
    def imag(self) -> Any:
        pass

imag() -> Any

Source code in numerary/types.py
225
226
227
@abstractproperty
def imag(self) -> Any:
    pass

real() -> Any

Source code in numerary/types.py
221
222
223
@abstractproperty
def real(self) -> Any:
    pass

_SupportsRealImagAsMethod

Bases: _Protocol

The non-caching version of SupportsRealImagAsMethod.

Source code in numerary/types.py
274
275
276
277
278
279
280
281
282
283
@runtime_checkable
class _SupportsRealImagAsMethod(_Protocol):
    r"""
    The non-caching version of
    [``SupportsRealImagAsMethod``][numerary.types.SupportsRealImagAsMethod].
    """

    @abstractmethod
    def as_real_imag(self) -> Tuple[Any, Any]:
        pass

as_real_imag() -> Tuple[Any, Any] abstractmethod

Source code in numerary/types.py
281
282
283
@abstractmethod
def as_real_imag(self) -> Tuple[Any, Any]:
    pass

_SupportsTrunc

Bases: _Protocol

The non-caching version of SupportsTrunc.

Source code in numerary/types.py
343
344
345
346
347
348
349
350
351
@runtime_checkable
class _SupportsTrunc(_Protocol):
    r"""
    The non-caching version of [``SupportsTrunc``][numerary.types.SupportsTrunc].
    """

    @abstractmethod
    def __trunc__(self) -> int:
        pass

__trunc__() -> int abstractmethod

Source code in numerary/types.py
349
350
351
@abstractmethod
def __trunc__(self) -> int:
    pass

_SupportsFloorCeil

Bases: _Protocol

The non-caching version of SupportsFloorCeil.

Source code in numerary/types.py
404
405
406
407
408
409
410
411
412
413
414
415
416
417
@runtime_checkable
class _SupportsFloorCeil(_Protocol):
    r"""
    The non-caching version of
    [``SupportsFloorCeil``][numerary.types.SupportsFloorCeil].
    """

    @abstractmethod
    def __floor__(self) -> int:
        pass

    @abstractmethod
    def __ceil__(self) -> int:
        pass

__ceil__() -> int abstractmethod

Source code in numerary/types.py
415
416
417
@abstractmethod
def __ceil__(self) -> int:
    pass

__floor__() -> int abstractmethod

Source code in numerary/types.py
411
412
413
@abstractmethod
def __floor__(self) -> int:
    pass

_SupportsDivmod

Bases: _Protocol, Generic[_T_co]

The non-caching version of SupportsDivmod.

Source code in numerary/types.py
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
@runtime_checkable
class _SupportsDivmod(
    _Protocol,
    Generic[_T_co],
):
    r"""
    The non-caching version of [``SupportsDivmod``][numerary.types.SupportsDivmod].
    """

    @abstractmethod
    def __divmod__(self, other: Any) -> Tuple[_T_co, _T_co]:
        pass

    @abstractmethod
    def __rdivmod__(self, other: Any) -> Tuple[_T_co, _T_co]:
        pass

__divmod__(other: Any) -> Tuple[_T_co, _T_co] abstractmethod

Source code in numerary/types.py
496
497
498
@abstractmethod
def __divmod__(self, other: Any) -> Tuple[_T_co, _T_co]:
    pass

__rdivmod__(other: Any) -> Tuple[_T_co, _T_co] abstractmethod

Source code in numerary/types.py
500
501
502
@abstractmethod
def __rdivmod__(self, other: Any) -> Tuple[_T_co, _T_co]:
    pass

_SupportsNumeratorDenominator

Bases: _Protocol

The non-caching version of SupportsNumeratorDenominator.

Source code in numerary/types.py
559
560
561
562
563
564
565
566
567
568
569
570
571
572
@runtime_checkable
class _SupportsNumeratorDenominator(_Protocol):
    r"""
    The non-caching version of
    [``SupportsNumeratorDenominator``][numerary.types.SupportsNumeratorDenominator].
    """

    @abstractproperty
    def numerator(self) -> int:
        pass

    @abstractproperty
    def denominator(self) -> int:
        pass

denominator() -> int

Source code in numerary/types.py
570
571
572
@abstractproperty
def denominator(self) -> int:
    pass

numerator() -> int

Source code in numerary/types.py
566
567
568
@abstractproperty
def numerator(self) -> int:
    pass

_SupportsNumeratorDenominatorMethods

Bases: _Protocol

The non-caching version of SupportsNumeratorDenominatorMethods.

Source code in numerary/types.py
626
627
628
629
630
631
632
633
634
635
636
637
638
639
@runtime_checkable
class _SupportsNumeratorDenominatorMethods(_Protocol):
    r"""
    The non-caching version of
    [``SupportsNumeratorDenominatorMethods``][numerary.types.SupportsNumeratorDenominatorMethods].
    """

    @abstractmethod
    def numerator(self) -> SupportsInt:
        pass

    @abstractmethod
    def denominator(self) -> SupportsInt:
        pass

denominator() -> SupportsInt abstractmethod

Source code in numerary/types.py
637
638
639
@abstractmethod
def denominator(self) -> SupportsInt:
    pass

numerator() -> SupportsInt abstractmethod

Source code in numerary/types.py
633
634
635
@abstractmethod
def numerator(self) -> SupportsInt:
    pass

_SupportsComplexOps

Bases: _Protocol, Generic[_T_co]

The non-caching version of SupportsComplexOps.

Source code in numerary/types.py
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
@runtime_checkable
class _SupportsComplexOps(
    _Protocol,
    Generic[_T_co],
):
    r"""
    The non-caching version of
    [``SupportsComplexOps``][numerary.types.SupportsComplexOps].
    """

    @abstractmethod
    def __add__(self, other: Any) -> _T_co:
        pass

    @abstractmethod
    def __radd__(self, other: Any) -> _T_co:
        pass

    @abstractmethod
    def __sub__(self, other: Any) -> _T_co:
        pass

    @abstractmethod
    def __rsub__(self, other: Any) -> _T_co:
        pass

    @abstractmethod
    def __mul__(self, other: Any) -> _T_co:
        pass

    @abstractmethod
    def __rmul__(self, other: Any) -> _T_co:
        pass

    @abstractmethod
    def __truediv__(self, other: Any) -> _T_co:
        pass

    @abstractmethod
    def __rtruediv__(self, other: Any) -> _T_co:
        pass

    @abstractmethod
    def __neg__(self) -> _T_co:
        pass

    @abstractmethod
    def __pos__(self) -> _T_co:
        pass

__add__(other: Any) -> _T_co abstractmethod

Source code in numerary/types.py
688
689
690
@abstractmethod
def __add__(self, other: Any) -> _T_co:
    pass

__mul__(other: Any) -> _T_co abstractmethod

Source code in numerary/types.py
704
705
706
@abstractmethod
def __mul__(self, other: Any) -> _T_co:
    pass

__neg__() -> _T_co abstractmethod

Source code in numerary/types.py
720
721
722
@abstractmethod
def __neg__(self) -> _T_co:
    pass

__pos__() -> _T_co abstractmethod

Source code in numerary/types.py
724
725
726
@abstractmethod
def __pos__(self) -> _T_co:
    pass

__radd__(other: Any) -> _T_co abstractmethod

Source code in numerary/types.py
692
693
694
@abstractmethod
def __radd__(self, other: Any) -> _T_co:
    pass

__rmul__(other: Any) -> _T_co abstractmethod

Source code in numerary/types.py
708
709
710
@abstractmethod
def __rmul__(self, other: Any) -> _T_co:
    pass

__rsub__(other: Any) -> _T_co abstractmethod

Source code in numerary/types.py
700
701
702
@abstractmethod
def __rsub__(self, other: Any) -> _T_co:
    pass

__rtruediv__(other: Any) -> _T_co abstractmethod

Source code in numerary/types.py
716
717
718
@abstractmethod
def __rtruediv__(self, other: Any) -> _T_co:
    pass

__sub__(other: Any) -> _T_co abstractmethod

Source code in numerary/types.py
696
697
698
@abstractmethod
def __sub__(self, other: Any) -> _T_co:
    pass

__truediv__(other: Any) -> _T_co abstractmethod

Source code in numerary/types.py
712
713
714
@abstractmethod
def __truediv__(self, other: Any) -> _T_co:
    pass

_SupportsComplexPow

Bases: _Protocol

The non-caching version of SupportsComplexPow.

Source code in numerary/types.py
779
780
781
782
783
784
785
786
787
788
789
790
791
792
@runtime_checkable
class _SupportsComplexPow(_Protocol):
    r"""
    The non-caching version of
    [``SupportsComplexPow``][numerary.types.SupportsComplexPow].
    """

    @abstractmethod
    def __pow__(self, exponent: Any) -> Any:
        pass

    @abstractmethod
    def __rpow__(self, exponent: Any) -> Any:
        pass

__pow__(exponent: Any) -> Any abstractmethod

Source code in numerary/types.py
786
787
788
@abstractmethod
def __pow__(self, exponent: Any) -> Any:
    pass

__rpow__(exponent: Any) -> Any abstractmethod

Source code in numerary/types.py
790
791
792
@abstractmethod
def __rpow__(self, exponent: Any) -> Any:
    pass

_SupportsRealOps

Bases: _Protocol, Generic[_T_co]

The non-caching version of SupportsRealOps.

Source code in numerary/types.py
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
@runtime_checkable
class _SupportsRealOps(
    _Protocol,
    Generic[_T_co],
):
    r"""
    The non-caching version of [``SupportsRealOps``][numerary.types.SupportsRealOps].
    """

    @abstractmethod
    def __lt__(self, other: Any) -> bool:
        pass

    @abstractmethod
    def __le__(self, other: Any) -> bool:
        pass

    @abstractmethod
    def __ge__(self, other: Any) -> bool:
        pass

    @abstractmethod
    def __gt__(self, other: Any) -> bool:
        pass

    @abstractmethod
    def __floordiv__(self, other: Any) -> Any:  # TODO(posita): should be int
        pass

    @abstractmethod
    def __rfloordiv__(self, other: Any) -> Any:  # TODO(posita): should be int
        pass

    @abstractmethod
    def __mod__(self, other: Any) -> _T_co:
        pass

    @abstractmethod
    def __rmod__(self, other: Any) -> _T_co:
        pass

__floordiv__(other: Any) -> Any abstractmethod

Source code in numerary/types.py
869
870
871
@abstractmethod
def __floordiv__(self, other: Any) -> Any:  # TODO(posita): should be int
    pass

__ge__(other: Any) -> bool abstractmethod

Source code in numerary/types.py
861
862
863
@abstractmethod
def __ge__(self, other: Any) -> bool:
    pass

__gt__(other: Any) -> bool abstractmethod

Source code in numerary/types.py
865
866
867
@abstractmethod
def __gt__(self, other: Any) -> bool:
    pass

__le__(other: Any) -> bool abstractmethod

Source code in numerary/types.py
857
858
859
@abstractmethod
def __le__(self, other: Any) -> bool:
    pass

__lt__(other: Any) -> bool abstractmethod

Source code in numerary/types.py
853
854
855
@abstractmethod
def __lt__(self, other: Any) -> bool:
    pass

__mod__(other: Any) -> _T_co abstractmethod

Source code in numerary/types.py
877
878
879
@abstractmethod
def __mod__(self, other: Any) -> _T_co:
    pass

__rfloordiv__(other: Any) -> Any abstractmethod

Source code in numerary/types.py
873
874
875
@abstractmethod
def __rfloordiv__(self, other: Any) -> Any:  # TODO(posita): should be int
    pass

__rmod__(other: Any) -> _T_co abstractmethod

Source code in numerary/types.py
881
882
883
@abstractmethod
def __rmod__(self, other: Any) -> _T_co:
    pass

_SupportsIntegralOps

Bases: _Protocol, Generic[_T_co]

The non-caching version of SupportsIntegralOps.

Source code in numerary/types.py
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
@runtime_checkable
class _SupportsIntegralOps(
    _Protocol,
    Generic[_T_co],
):
    r"""
    The non-caching version of
    [``SupportsIntegralOps``][numerary.types.SupportsIntegralOps].
    """

    @abstractmethod
    def __lshift__(self, other: Any) -> _T_co:
        pass

    @abstractmethod
    def __rlshift__(self, other: Any) -> _T_co:
        pass

    @abstractmethod
    def __rshift__(self, other: Any) -> _T_co:
        pass

    @abstractmethod
    def __rrshift__(self, other: Any) -> _T_co:
        pass

    @abstractmethod
    def __and__(self, other: Any) -> _T_co:
        pass

    @abstractmethod
    def __rand__(self, other: Any) -> _T_co:
        pass

    @abstractmethod
    def __xor__(self, other: Any) -> _T_co:
        pass

    @abstractmethod
    def __rxor__(self, other: Any) -> _T_co:
        pass

    @abstractmethod
    def __or__(self, other: Any) -> _T_co:
        pass

    @abstractmethod
    def __ror__(self, other: Any) -> _T_co:
        pass

    @abstractmethod
    def __invert__(self) -> _T_co:
        pass

__and__(other: Any) -> _T_co abstractmethod

Source code in numerary/types.py
964
965
966
@abstractmethod
def __and__(self, other: Any) -> _T_co:
    pass

__invert__() -> _T_co abstractmethod

Source code in numerary/types.py
988
989
990
@abstractmethod
def __invert__(self) -> _T_co:
    pass

__lshift__(other: Any) -> _T_co abstractmethod

Source code in numerary/types.py
948
949
950
@abstractmethod
def __lshift__(self, other: Any) -> _T_co:
    pass

__or__(other: Any) -> _T_co abstractmethod

Source code in numerary/types.py
980
981
982
@abstractmethod
def __or__(self, other: Any) -> _T_co:
    pass

__rand__(other: Any) -> _T_co abstractmethod

Source code in numerary/types.py
968
969
970
@abstractmethod
def __rand__(self, other: Any) -> _T_co:
    pass

__rlshift__(other: Any) -> _T_co abstractmethod

Source code in numerary/types.py
952
953
954
@abstractmethod
def __rlshift__(self, other: Any) -> _T_co:
    pass

__ror__(other: Any) -> _T_co abstractmethod

Source code in numerary/types.py
984
985
986
@abstractmethod
def __ror__(self, other: Any) -> _T_co:
    pass

__rrshift__(other: Any) -> _T_co abstractmethod

Source code in numerary/types.py
960
961
962
@abstractmethod
def __rrshift__(self, other: Any) -> _T_co:
    pass

__rshift__(other: Any) -> _T_co abstractmethod

Source code in numerary/types.py
956
957
958
@abstractmethod
def __rshift__(self, other: Any) -> _T_co:
    pass

__rxor__(other: Any) -> _T_co abstractmethod

Source code in numerary/types.py
976
977
978
@abstractmethod
def __rxor__(self, other: Any) -> _T_co:
    pass

__xor__(other: Any) -> _T_co abstractmethod

Source code in numerary/types.py
972
973
974
@abstractmethod
def __xor__(self, other: Any) -> _T_co:
    pass

_SupportsIntegralPow

Bases: _Protocol

The non-caching version of SupportsIntegralPow.

Source code in numerary/types.py
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
@runtime_checkable
class _SupportsIntegralPow(_Protocol):
    r"""
    The non-caching version of
    [``SupportsIntegralPow``][numerary.types.SupportsIntegralPow].
    """

    @abstractmethod
    def __pow__(self, exponent: Any, modulus: Optional[Any] = None) -> Any:
        pass

    @abstractmethod
    def __rpow__(self, exponent: Any, modulus: Optional[Any] = None) -> Any:
        pass

__pow__(exponent: Any, modulus: Optional[Any] = None) -> Any abstractmethod

Source code in numerary/types.py
1046
1047
1048
@abstractmethod
def __pow__(self, exponent: Any, modulus: Optional[Any] = None) -> Any:
    pass

__rpow__(exponent: Any, modulus: Optional[Any] = None) -> Any abstractmethod

Source code in numerary/types.py
1050
1051
1052
@abstractmethod
def __rpow__(self, exponent: Any, modulus: Optional[Any] = None) -> Any:
    pass