Skip to content

Commit 1ebeea0

Browse files
committed
Split SupportsRealImag into SupportsRealImagProperties and SupportsRealImagAsMethod
Now ``sympy.core.numbers`` primitives are adequately supported (excepting general false positives; see #5). Fixes #4.
1 parent 3600886 commit 1ebeea0

15 files changed

+401
-172
lines changed

README.md

+18-2
Original file line numberDiff line numberDiff line change
@@ -368,8 +368,24 @@ True
368368
True
369369
>>> hasattr(pants_on_fire, "real") or hasattr(pants_on_fire, "imag") # somebody's tellin' stories
370370
False
371-
>>> from numerary.types import SupportsRealImag
372-
>>> real_imag: SupportsRealImag = pants_on_fire # fails to detect the lie
371+
>>> from numerary.types import SupportsRealImagProperties
372+
>>> real_imag: SupportsRealImagProperties = pants_on_fire # fails to detect the lie
373+
>>> real_imag.real
374+
Traceback (most recent call last):
375+
...
376+
AttributeError: 'One' object has no attribute 'real'
377+
378+
```
379+
380+
In this particular case, ``numerary`` provides us with a defensive mechanism.
381+
382+
``` python
383+
>>> from numerary.types import SupportsRealImagMixedU, real, imag
384+
>>> real_imag_defense: SupportsRealImagMixedU = pants_on_fire
385+
>>> real(real_imag_defense)
386+
1
387+
>>> imag(real_imag)
388+
0
373389

374390
```
375391

docs/notes.md

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
## [0.1.2](https://github.com/posita/numerary/releases/tag/v0.1.2)
1919

20+
* Splits ``SupportsRealImag`` into [``SupportsRealImagProperties``][numerary.types.SupportsRealImagProperties] and [``SupportsRealImagAsMethod``][numerary.types.SupportsRealImagAsMethod] and provides the [``real``][numerary.types.real] and [``imag``][numerary.types.imag] helper functions for better support of ``sympy.core.numbers`` primitives.
21+
2022
## [0.1.1](https://github.com/posita/numerary/releases/tag/v0.1.1)
2123

2224
* Removes obsoleted ``…SCT`` aliases.

docs/numerary.types.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ from numerary.bt import beartype # will resolve to the identity decorator if be
6666
- "SupportsIndex"
6767
- "SupportsRound"
6868
- "SupportsConjugate"
69-
- "SupportsRealImag"
69+
- "SupportsRealImagProperties"
70+
- "SupportsRealImagAsMethod"
7071
- "SupportsTrunc"
7172
- "SupportsFloorCeil"
7273
- "SupportsDivmod"
@@ -77,6 +78,8 @@ from numerary.bt import beartype # will resolve to the identity decorator if be
7778
- "SupportsRealOps"
7879
- "SupportsIntegralOps"
7980
- "SupportsIntegralPow"
81+
- "real"
82+
- "imag"
8083
- "trunc"
8184
- "floor"
8285
- "ceil"
@@ -102,7 +105,10 @@ from numerary.bt import beartype # will resolve to the identity decorator if be
102105
- "_SupportsIndex"
103106
- "_SupportsRound"
104107
- "_SupportsConjugate"
105-
- "_SupportsRealImag"
108+
- "_SupportsRealImagProperties"
109+
- "_SupportsRealImagAsMethod"
110+
- "SupportsRealImagMixedT"
111+
- "SupportsRealImagMixedU"
106112
- "_SupportsTrunc"
107113
- "_SupportsFloorCeil"
108114
- "_SupportsDivmod"

docs/perf_rational_big_protocol.ipy

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ from numerary.types import ( # "raw" (non-caching) versions
55
_SupportsConjugate,
66
_SupportsFloorCeil,
77
_SupportsDivmod,
8-
_SupportsRealImag,
8+
_SupportsRealImagProperties,
99
_SupportsRealOps,
1010
_SupportsTrunc,
1111
)
@@ -33,7 +33,7 @@ class SupportsLotsOfNumberStuff(
3333
_SupportsTrunc,
3434
_SupportsFloorCeil,
3535
_SupportsConjugate,
36-
_SupportsRealImag,
36+
_SupportsRealImagProperties,
3737
SupportsAbs,
3838
SupportsFloat,
3939
SupportsComplex,

docs/perf_rational_big_protocol.out

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
%timeit isinstance(builtins.int(1), SupportsLotsOfNumberStuff)
2-
132 µs ± 1.15 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)
2+
135 µs ± 1.02 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)
33
%timeit isinstance(fractions.Fraction(2), SupportsLotsOfNumberStuff)
4-
139 µs ± 2.01 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)
4+
146 µs ± 14.4 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)
55
%timeit isinstance(builtins.float(3.0), SupportsLotsOfNumberStuff)
6-
131 µs ± 1.13 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)
6+
134 µs ± 1.84 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)

0 commit comments

Comments
 (0)