Skip to content

Commit

Permalink
Give this pathetic thing some upgrade love
Browse files Browse the repository at this point in the history
* (Temporarily?) acknowledges lack of PyPy support
  • Loading branch information
posita committed Aug 5, 2024
1 parent 6761d0e commit 95e8717
Show file tree
Hide file tree
Showing 10 changed files with 173 additions and 259 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/on-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ jobs:
timeout-minutes: 30
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "pypy-3.8", "pypy-3.9"]
python-version: [
"3.9", "3.10", "3.11", "3.12",
# "pypy-3.9", "pypy-3.10", # see <https://github.com/beartype/beartype/issues/324>
]
steps:
- uses: actions/checkout@v2
with:
Expand Down
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repos:
- id: check-hooks-apply
- id: check-useless-excludes
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.6.0
hooks:
- id: end-of-file-fixer
# See <https://docs.python.org/3/library/re.html#re.X>
Expand Down Expand Up @@ -39,14 +39,14 @@ repos:
- id: check-xml
- id: check-yaml
- repo: https://github.com/psf/black
rev: 23.7.0
rev: 24.8.0
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: 5.12.0
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
rev: 7.1.0
hooks:
- id: flake8
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## The MIT License (MIT)

Copyright © 2015-2022 [Matt Bogosian](mailto:[email protected]?Subject=numerary)
Copyright © 2015-2024 [Matt Bogosian](mailto:[email protected]?Subject=numerary)
([**@posita**](https://github.com/posita)).

Permission is hereby granted, free of charge, to any person obtaining a copy of this
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ Not very well, unfortunately, at least not on its own.
... assert isinstance(arg, SupportsFloorCeil)
... return __floor__(arg)

>>> my_floor_func(float(1.2)) # works in 3.8+
>>> my_floor_func(float(1.2)) # works in 3.9+
1

```
Expand Down Expand Up @@ -552,8 +552,8 @@ Alternately, you can download [the source](https://github.com/posita/numerary) a

``numerary`` requires a relatively modern version of Python:

* [CPython](https://www.python.org/) (3.8+)
* [PyPy](http://pypy.org/) (CPython 3.8+ compatible)
* [CPython](https://www.python.org/) (3.9+)
* ~~[PyPy](http://pypy.org/) (CPython 3.9+ compatible)~~ *See [beartype/beartype#324](https://github.com/beartype/beartype/issues/324)*

It has the following runtime dependencies:

Expand Down
80 changes: 26 additions & 54 deletions docs/numerary.types.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,69 +30,41 @@
show_root_toc_entry: false
selection:
members:
- "Protocol"
- "RationalLike"
- "RationalLikeMethods"
- "RationalLikeMixedT"
- "RationalLikeMixedU"
- "SupportsAbs"
- "SupportsComplex"
- "SupportsFloat"
- "SupportsInt"
- "SupportsIndex"
- "SupportsRound"
- "SupportsComplexOps"
- "SupportsComplexPow"
- "SupportsConjugate"
- "SupportsRealImag"
- "SupportsRealImagAsMethod"
- "SupportsTrunc"
- "SupportsFloorCeil"
- "SupportsDivmod"
- "SupportsFloat"
- "SupportsFloorCeil"
- "SupportsIndex"
- "SupportsInt"
- "SupportsIntegralOps"
- "SupportsIntegralPow"
- "SupportsNumeratorDenominator"
- "SupportsNumeratorDenominatorMethods"
- "SupportsComplexOps"
- "SupportsComplexPow"
- "SupportsNumeratorDenominatorMixedT"
- "SupportsNumeratorDenominatorMixedT"
- "SupportsNumeratorDenominatorMixedU"
- "SupportsNumeratorDenominatorMixedU"
- "SupportsRealImag"
- "SupportsRealImagAsMethod"
- "SupportsRealImagMixedT"
- "SupportsRealImagMixedU"
- "SupportsRealOps"
- "SupportsIntegralOps"
- "SupportsIntegralPow"
- "Protocol"
- "real"
- "imag"
- "SupportsRound"
- "SupportsTrunc"
- "__ceil__"
- "__floor__"
- "__pow__"
- "__trunc__"
- "__floor__"
- "__ceil__"
- "numerator"
- "denominator"

<!---
See <https://github.com/mkdocstrings/mkdocstrings/issues/333>
-->
::: numerary.types
rendering:
show_if_no_docstring: true
show_root_heading: false
show_root_toc_entry: false
selection:
members:
- "RationalLikeMixedT"
- "RationalLikeMixedU"
- "_SupportsAbs"
- "_SupportsComplex"
- "_SupportsFloat"
- "_SupportsInt"
- "_SupportsIndex"
- "_SupportsRound"
- "_SupportsConjugate"
- "_SupportsRealImag"
- "_SupportsRealImagAsMethod"
- "SupportsRealImagMixedT"
- "SupportsRealImagMixedU"
- "_SupportsTrunc"
- "_SupportsFloorCeil"
- "_SupportsDivmod"
- "_SupportsNumeratorDenominator"
- "_SupportsNumeratorDenominatorMethods"
- "SupportsNumeratorDenominatorMixedT"
- "SupportsNumeratorDenominatorMixedU"
- "_SupportsComplexOps"
- "_SupportsComplexPow"
- "_SupportsRealOps"
- "_SupportsIntegralOps"
- "_SupportsIntegralPow"
- "imag"
- "numerator"
- "real"
6 changes: 3 additions & 3 deletions numerary/bt.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def identity(__: _T) -> _T:
f"""unrecognized value ({_NUMERARY_BEARTYPE}) for NUMERARY_BEARTYPE environment variable (should be "{'", "'.join(_truthy + _falsy)}", or an integer)"""
)

if not TYPE_CHECKING and _use_beartype_internally:
if TYPE_CHECKING or not _use_beartype_internally:
beartype = identity
else:
from beartype import beartype as _beartype

beartype = _beartype
else:
beartype = identity
68 changes: 33 additions & 35 deletions numerary/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ class SupportsConjugate(
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.)
(``_SupportsConjugate`` is the raw, non-caching version that defines the actual
methods.)
``` python
>>> from typing import TypeVar
Expand Down Expand Up @@ -237,8 +237,8 @@ class SupportsRealImag(
[``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.)
(``_SupportsRealImag`` is the raw, non-caching version that defines the actual
methods.)
``` python
>>> from typing import Any, Tuple, TypeVar
Expand Down Expand Up @@ -290,8 +290,8 @@ class SupportsRealImagAsMethod(
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.)
(``_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.
Expand Down Expand Up @@ -361,8 +361,8 @@ class SupportsTrunc(
See also the [``__trunc__`` helper function][numerary.types.__trunc__].
([``_SupportsTrunc``][numerary.types._SupportsTrunc] is the raw, non-caching version
that defines the actual methods.)
(``_SupportsTrunc`` is the raw, non-caching version that defines the actual
methods.)
``` python
>>> from typing import Any, Tuple, TypeVar
Expand Down Expand Up @@ -428,8 +428,8 @@ class SupportsFloorCeil(
[``__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.)
(``_SupportsFloorCeil`` is the raw, non-caching version that defines the actual
methods.)
!!! note
Expand Down Expand Up @@ -514,8 +514,8 @@ class SupportsDivmod(
[``__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.)
(``_SupportsDivmod`` is the raw, non-caching version that defines the actual
methods.)
``` python
>>> from typing import Any, Tuple, TypeVar
Expand Down Expand Up @@ -583,8 +583,8 @@ class SupportsNumeratorDenominator(
[``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.)
(``_SupportsNumeratorDenominator`` is the raw, non-caching version that defines the
actual properties.)
``` python
>>> from typing import Any, Tuple, TypeVar
Expand Down Expand Up @@ -647,8 +647,8 @@ class SupportsNumeratorDenominatorMethods(
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.)
(``_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.
Expand Down Expand Up @@ -679,8 +679,7 @@ class _SupportsComplexOps(
Generic[_T_co],
):
r"""
The non-caching version of
[``SupportsComplexOps``][numerary.types.SupportsComplexOps].
The non-caching version of ``SupportsComplexOps``.
"""

@abstractmethod
Expand Down Expand Up @@ -736,8 +735,8 @@ class SupportsComplexOps(
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.)
(``_SupportsComplexOps`` is the raw, non-caching version that defines the actual
methods.)
``` python
>>> from typing import Any, Tuple, TypeVar
Expand Down Expand Up @@ -801,8 +800,8 @@ class SupportsComplexPow(
[``__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.)
(``_SupportsComplexPow`` is the raw, non-caching version that defines the actual
methods.)
``` python
>>> from typing import Any, Tuple, TypeVar
Expand Down Expand Up @@ -893,8 +892,8 @@ class SupportsRealOps(
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.)
(``_SupportsRealOps`` is the raw, non-caching version that defines the actual
methods.)
``` python
>>> from typing import Any, Tuple, TypeVar
Expand Down Expand Up @@ -1000,8 +999,8 @@ class SupportsIntegralOps(
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.)
(``_SupportsIntegralOps`` is the raw, non-caching version that defines the actual
methods.)
``` python
>>> from typing import Any, Tuple, TypeVar
Expand Down Expand Up @@ -1062,8 +1061,8 @@ class SupportsIntegralPow(
[``__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.)
(``_SupportsIntegralPow`` is the raw, non-caching version that defines the actual
methods.)
``` python
>>> from typing import Any, Tuple, TypeVar
Expand Down Expand Up @@ -1317,7 +1316,7 @@ def __hash__(self) -> int:
``` python
RationalLikeMixedU = {RationalLikeMixedU!r}
RationalLikeMixedT = ({", ".join(cls.__name__ for cls in RationalLikeMixedT)})
RationalLikeMixedT = ({", ".join(cls.__name__ for cls in RationalLikeMixedT)})
```
"""

Expand Down Expand Up @@ -1468,20 +1467,19 @@ def imag(operand: SupportsRealImagMixedU):
# TODO(posita): Are these sufficient? Could these be more specific? See:
# <https://github.com/python/typeshed/issues/6303#issuecomment-969392257>.
@overload
def __pow__(arg: Union[SupportsComplexPow, SupportsIntegralPow], exponent: Any) -> Any:
...
def __pow__(
arg: Union[SupportsComplexPow, SupportsIntegralPow], exponent: Any
) -> Any: ...


@overload
def __pow__(
arg: Union[SupportsComplexPow, SupportsIntegralPow], exponent: Any, modulus: None
) -> Any:
...
) -> Any: ...


@overload
def __pow__(arg: SupportsIntegralPow, exponent: Any, modulus: Any) -> Any:
...
def __pow__(arg: SupportsIntegralPow, exponent: Any, modulus: Any) -> Any: ...


@beartype
Expand Down
Loading

0 comments on commit 95e8717

Please sign in to comment.