From d3c53199ce21a34beda990ff3dc24fdf0780edcd Mon Sep 17 00:00:00 2001 From: Matt Bogosian Date: Sun, 4 Aug 2024 15:46:39 -0500 Subject: [PATCH] Give this pathetic thing some upgrade love --- .github/workflows/on-push.yaml | 5 +- .pre-commit-config.yaml | 8 +- LICENSE | 2 +- README.md | 6 +- docs/numerary.types.md | 80 +++++-------- numerary/bt.py | 6 +- numerary/types.py | 66 +++++------ setup.cfg | 21 ++-- tests/numberwang.py | 208 ++++++++++++--------------------- tests/test_integral_like.py | 32 ++--- 10 files changed, 174 insertions(+), 260 deletions(-) diff --git a/.github/workflows/on-push.yaml b/.github/workflows/on-push.yaml index f23678f..203dc45 100644 --- a/.github/workflows/on-push.yaml +++ b/.github/workflows/on-push.yaml @@ -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 + ] steps: - uses: actions/checkout@v2 with: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3b84e9a..93b01b1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 @@ -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 diff --git a/LICENSE b/LICENSE index bd5b875..9eb3ac2 100644 --- a/LICENSE +++ b/LICENSE @@ -2,7 +2,7 @@ ## The MIT License (MIT) -Copyright © 2015-2022 [Matt Bogosian](mailto:matt@bogosian.net?Subject=numerary) +Copyright © 2015-2024 [Matt Bogosian](mailto:matt@bogosian.net?Subject=numerary) ([**@posita**](https://github.com/posita)). Permission is hereby granted, free of charge, to any person obtaining a copy of this diff --git a/README.md b/README.md index 555fed1..1a0d0bf 100644 --- a/README.md +++ b/README.md @@ -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 ``` @@ -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: diff --git a/docs/numerary.types.md b/docs/numerary.types.md index 10b26e3..b083f71 100644 --- a/docs/numerary.types.md +++ b/docs/numerary.types.md @@ -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" - - -::: 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" diff --git a/numerary/bt.py b/numerary/bt.py index f904956..37a40dc 100644 --- a/numerary/bt.py +++ b/numerary/bt.py @@ -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 diff --git a/numerary/types.py b/numerary/types.py index 21de71d..f1fe472 100644 --- a/numerary/types.py +++ b/numerary/types.py @@ -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 @@ -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 @@ -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. @@ -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 @@ -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 @@ -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 @@ -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 @@ -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. @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -1468,20 +1467,19 @@ def imag(operand: SupportsRealImagMixedU): # TODO(posita): Are these sufficient? Could these be more specific? See: # . @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 diff --git a/setup.cfg b/setup.cfg index 357b7ff..dc59100 100644 --- a/setup.cfg +++ b/setup.cfg @@ -28,12 +28,12 @@ classifiers = License :: OSI Approved :: MIT License Operating System :: OS Independent Programming Language :: Python - Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 Programming Language :: Python :: 3.11 + Programming Language :: Python :: 3.12 Programming Language :: Python :: Implementation :: CPython - Programming Language :: Python :: Implementation :: PyPy + # Programming Language :: Python :: Implementation :: PyPy license = MIT License license_files = LICENSE description = Python hacks for type-checking numbers @@ -43,7 +43,7 @@ long_description_content_type = text/markdown; charset=UTF-8 [options] # --------------------------------------------------------------------------- packages = numerary -python_requires = >=3.8 +python_requires = >=3.9 install_requires = beartype ~=0.15 @@ -62,19 +62,19 @@ numerary = py.typed [tox:tox] # --------------------------------------------------------------------------- -envlist = check, py{39,310,311}{,-lint}{,-beartype}, py{38,py38,py39}{,-beartype} +envlist = check, py{39,310,311,312}{,-lint}{,-beartype} # , pypy{39,310} # see skipsdist = true skip_missing_interpreters = true [gh-actions] # ------------------------------------------------------------------------ python = - 3.8: py38{,-beartype} 3.9: py39{,-lint}{,-beartype} 3.10: check, py310{,-lint}{,-beartype} 3.11: py311{,-lint}{,-beartype} - pypy-3.8: pypy38{,-beartype} - pypy-3.9: pypy39{,-beartype} + 3.12: py312{,-lint}{,-beartype} + # pypy-3.9: pypy39 # see + # pypy-3.10: pypy310 # see fail_on_no_env = True [testenv] # --------------------------------------------------------------------------- @@ -97,7 +97,7 @@ deps = sympy~=1.9 !debug: pytest-cov !debug: pytest-xdist - !pypy38-!pypy39: numpy + # !pypy39-!pypy310: numpy # see passenv = PYTHONBREAKPOINT setenv = @@ -142,7 +142,7 @@ deps = allowlist_externals = rm -[testenv:py{39,310,311}-lint{,-beartype}] # ------------------------------------------- +[testenv:py{39,310,311,312}-lint{,-beartype}] # --------------------------------------- commands = pre-commit run --all-files --show-diff-on-failure @@ -153,7 +153,6 @@ deps = mypy~=1.0 pre-commit sympy - !pypy38-!pypy39: numpy allowlist_externals = {toxinidir}/helpers/mypy-doctests.py @@ -165,6 +164,8 @@ allowlist_externals = ignore = # whitespace before ':' E203 + # multiple statements on one line + E704 # line too long (... > ... characters) E501 # line break occurred before a binary operator diff --git a/tests/numberwang.py b/tests/numberwang.py index fa4ca1d..3be949f 100644 --- a/tests/numberwang.py +++ b/tests/numberwang.py @@ -117,16 +117,14 @@ def __hash__(self) -> int: return hash((type(self).__name__, self.val)) @overload - def __add__(self, other: _IntegralT) -> _IntegralT: # type: ignore[misc] + def __add__(self, other: _IntegralT) -> _IntegralT: # type: ignore [overload-overlap] ... @overload - def __add__(self, other: _RealT) -> _RealT: - ... + def __add__(self, other: _RealT) -> _RealT: ... @overload - def __add__(self, other: Decimal) -> Decimal: - ... + def __add__(self, other: Decimal) -> Decimal: ... @beartype def __add__(self, other): @@ -145,16 +143,14 @@ def __add__(self, other): return __add__(self.val, other) @overload - def __radd__(self, other: _IntegralT) -> _IntegralT: # type: ignore [misc] + def __radd__(self, other: _IntegralT) -> _IntegralT: # type: ignore [overload-overlap] ... @overload - def __radd__(self, other: _RealT) -> _RealT: - ... + def __radd__(self, other: _RealT) -> _RealT: ... @overload - def __radd__(self, other: Decimal) -> Decimal: - ... + def __radd__(self, other: Decimal) -> Decimal: ... @beartype def __radd__(self, other): @@ -173,16 +169,14 @@ def __radd__(self, other): return __add__(other, self.val) @overload - def __sub__(self, other: _IntegralT) -> _IntegralT: # type: ignore [misc] + def __sub__(self, other: _IntegralT) -> _IntegralT: # type: ignore [overload-overlap] ... @overload - def __sub__(self, other: _RealT) -> _RealT: - ... + def __sub__(self, other: _RealT) -> _RealT: ... @overload - def __sub__(self, other: Decimal) -> Decimal: - ... + def __sub__(self, other: Decimal) -> Decimal: ... @beartype def __sub__(self, other): @@ -201,16 +195,14 @@ def __sub__(self, other): return __sub__(self.val, other) @overload - def __rsub__(self, other: _IntegralT) -> _IntegralT: # type: ignore [misc] + def __rsub__(self, other: _IntegralT) -> _IntegralT: # type: ignore [overload-overlap] ... @overload - def __rsub__(self, other: _RealT) -> _RealT: - ... + def __rsub__(self, other: _RealT) -> _RealT: ... @overload - def __rsub__(self, other: Decimal) -> Decimal: - ... + def __rsub__(self, other: Decimal) -> Decimal: ... @beartype def __rsub__(self, other): @@ -229,16 +221,14 @@ def __rsub__(self, other): return __sub__(other, self.val) @overload - def __mul__(self, other: _IntegralT) -> _IntegralT: # type: ignore [misc] + def __mul__(self, other: _IntegralT) -> _IntegralT: # type: ignore [overload-overlap] ... @overload - def __mul__(self, other: _RealT) -> _RealT: - ... + def __mul__(self, other: _RealT) -> _RealT: ... @overload - def __mul__(self, other: Decimal) -> Decimal: - ... + def __mul__(self, other: Decimal) -> Decimal: ... @beartype def __mul__(self, other): @@ -257,16 +247,14 @@ def __mul__(self, other): return __mul__(self.val, other) @overload - def __rmul__(self, other: _IntegralT) -> _IntegralT: # type: ignore [misc] + def __rmul__(self, other: _IntegralT) -> _IntegralT: # type: ignore [overload-overlap] ... @overload - def __rmul__(self, other: _RealT) -> _RealT: - ... + def __rmul__(self, other: _RealT) -> _RealT: ... @overload - def __rmul__(self, other: Decimal) -> Decimal: - ... + def __rmul__(self, other: Decimal) -> Decimal: ... @beartype def __rmul__(self, other): @@ -285,12 +273,10 @@ def __rmul__(self, other): return __mul__(other, self.val) @overload - def __truediv__(self, other: _RealT) -> _RealT: - ... + def __truediv__(self, other: _RealT) -> _RealT: ... @overload - def __truediv__(self, other: Decimal) -> Decimal: - ... + def __truediv__(self, other: Decimal) -> Decimal: ... @beartype def __truediv__(self, other): @@ -307,12 +293,10 @@ def __truediv__(self, other): return __truediv__(self.val, other) @overload - def __rtruediv__(self, other: _RealT) -> _RealT: - ... + def __rtruediv__(self, other: _RealT) -> _RealT: ... @overload - def __rtruediv__(self, other: Decimal) -> Decimal: - ... + def __rtruediv__(self, other: Decimal) -> Decimal: ... @beartype def __rtruediv__(self, other): @@ -329,16 +313,14 @@ def __rtruediv__(self, other): return __truediv__(other, self.val) @overload - def __floordiv__(self, other: _IntegralT) -> _IntegralT: # type: ignore [misc] + def __floordiv__(self, other: _IntegralT) -> _IntegralT: # type: ignore [overload-overlap] ... @overload - def __floordiv__(self, other: _RealT) -> _RealT: - ... + def __floordiv__(self, other: _RealT) -> _RealT: ... @overload - def __floordiv__(self, other: Decimal) -> Decimal: - ... + def __floordiv__(self, other: Decimal) -> Decimal: ... @beartype def __floordiv__(self, other): @@ -357,16 +339,14 @@ def __floordiv__(self, other): return __floordiv__(self.val, other) @overload - def __rfloordiv__(self, other: _IntegralT) -> _IntegralT: # type: ignore [misc] + def __rfloordiv__(self, other: _IntegralT) -> _IntegralT: # type: ignore [overload-overlap] ... @overload - def __rfloordiv__(self, other: _RealT) -> _RealT: # type: ignore [misc] - ... + def __rfloordiv__(self, other: _RealT) -> _RealT: ... @overload - def __rfloordiv__(self, other: Decimal) -> Decimal: - ... + def __rfloordiv__(self, other: Decimal) -> Decimal: ... @beartype def __rfloordiv__(self, other): @@ -385,16 +365,14 @@ def __rfloordiv__(self, other): return __floordiv__(other, self.val) @overload - def __mod__(self, other: _IntegralT) -> _IntegralT: # type: ignore [misc] + def __mod__(self, other: _IntegralT) -> _IntegralT: # type: ignore [overload-overlap] ... @overload - def __mod__(self, other: _RealT) -> _RealT: - ... + def __mod__(self, other: _RealT) -> _RealT: ... @overload - def __mod__(self, other: Decimal) -> Decimal: - ... + def __mod__(self, other: Decimal) -> Decimal: ... @beartype def __mod__(self, other): @@ -413,16 +391,14 @@ def __mod__(self, other): return __mod__(self.val, other) @overload - def __rmod__(self, other: _IntegralT) -> _IntegralT: # type: ignore [misc] + def __rmod__(self, other: _IntegralT) -> _IntegralT: # type: ignore [overload-overlap] ... @overload - def __rmod__(self, other: _RealT) -> _RealT: - ... + def __rmod__(self, other: _RealT) -> _RealT: ... @overload - def __rmod__(self, other: Decimal) -> Decimal: - ... + def __rmod__(self, other: Decimal) -> Decimal: ... @beartype def __rmod__(self, other): @@ -441,18 +417,15 @@ def __rmod__(self, other): return __mod__(other, self.val) @overload - def __pow__( # type: ignore [misc] + def __pow__( # type: ignore [overload-overlap] self, other: _IntegralT, modulo: Optional[_IntegralT] = None - ) -> _IntegralT: - ... + ) -> _IntegralT: ... @overload - def __pow__(self, other: _RealT) -> _RealT: - ... + def __pow__(self, other: _RealT) -> _RealT: ... @overload - def __pow__(self, other: Decimal) -> Decimal: - ... + def __pow__(self, other: Decimal) -> Decimal: ... @beartype def __pow__(self, other, modulo=None): @@ -471,18 +444,15 @@ def __pow__(self, other, modulo=None): return pow(self.val, other, modulo) @overload - def __rpow__( # type: ignore [misc] + def __rpow__( # type: ignore [overload-overlap] self, other: _IntegralT, modulo: Optional[_IntegralT] = None - ) -> _IntegralT: - ... + ) -> _IntegralT: ... @overload - def __rpow__(self, other: _RealT) -> _RealT: - ... + def __rpow__(self, other: _RealT) -> _RealT: ... @overload - def __rpow__(self, other: Decimal) -> Decimal: - ... + def __rpow__(self, other: Decimal) -> Decimal: ... @beartype def __rpow__(self, other, modulo=None): @@ -670,7 +640,7 @@ class NumberwangRegistered(Numberwang): assert issubclass(NumberwangRegistered, Integral) -class NumberwangDerived(NumberwangBase, Integral): # type: ignore [misc] +class NumberwangDerived(NumberwangBase, Integral): __slots__: Any = () @@ -723,12 +693,10 @@ def __hash__(self) -> int: return hash(self.val) @overload - def __add__(self, other: _RealT) -> _RealT: - ... + def __add__(self, other: _RealT) -> _RealT: ... @overload - def __add__(self, other: Decimal) -> Decimal: - ... + def __add__(self, other: Decimal) -> Decimal: ... @beartype def __add__(self, other): @@ -738,12 +706,10 @@ def __add__(self, other): return __add__(self.val, other) @overload - def __radd__(self, other: _RealT) -> _RealT: - ... + def __radd__(self, other: _RealT) -> _RealT: ... @overload - def __radd__(self, other: Decimal) -> Decimal: - ... + def __radd__(self, other: Decimal) -> Decimal: ... @beartype def __radd__(self, other): @@ -753,12 +719,10 @@ def __radd__(self, other): return __add__(other, self.val) @overload - def __sub__(self, other: _RealT) -> _RealT: - ... + def __sub__(self, other: _RealT) -> _RealT: ... @overload - def __sub__(self, other: Decimal) -> Decimal: - ... + def __sub__(self, other: Decimal) -> Decimal: ... @beartype def __sub__(self, other): @@ -768,12 +732,10 @@ def __sub__(self, other): return __sub__(self.val, other) @overload - def __rsub__(self, other: _RealT) -> _RealT: - ... + def __rsub__(self, other: _RealT) -> _RealT: ... @overload - def __rsub__(self, other: Decimal) -> Decimal: - ... + def __rsub__(self, other: Decimal) -> Decimal: ... @beartype def __rsub__(self, other): @@ -783,12 +745,10 @@ def __rsub__(self, other): return __sub__(other, self.val) @overload - def __mul__(self, other: _RealT) -> _RealT: - ... + def __mul__(self, other: _RealT) -> _RealT: ... @overload - def __mul__(self, other: Decimal) -> Decimal: - ... + def __mul__(self, other: Decimal) -> Decimal: ... @beartype def __mul__(self, other): @@ -798,12 +758,10 @@ def __mul__(self, other): return __mul__(self.val, other) @overload - def __rmul__(self, other: _RealT) -> _RealT: - ... + def __rmul__(self, other: _RealT) -> _RealT: ... @overload - def __rmul__(self, other: Decimal) -> Decimal: - ... + def __rmul__(self, other: Decimal) -> Decimal: ... @beartype def __rmul__(self, other): @@ -813,12 +771,10 @@ def __rmul__(self, other): return __mul__(other, self.val) @overload - def __truediv__(self, other: _RealT) -> _RealT: - ... + def __truediv__(self, other: _RealT) -> _RealT: ... @overload - def __truediv__(self, other: Decimal) -> Decimal: - ... + def __truediv__(self, other: Decimal) -> Decimal: ... @beartype def __truediv__(self, other): @@ -828,12 +784,10 @@ def __truediv__(self, other): return __truediv__(self.val, other) @overload - def __rtruediv__(self, other: _RealT) -> _RealT: - ... + def __rtruediv__(self, other: _RealT) -> _RealT: ... @overload - def __rtruediv__(self, other: Decimal) -> Decimal: - ... + def __rtruediv__(self, other: Decimal) -> Decimal: ... @beartype def __rtruediv__(self, other): @@ -843,12 +797,10 @@ def __rtruediv__(self, other): return __truediv__(other, self.val) @overload - def __floordiv__(self, other: _RealT) -> _RealT: - ... + def __floordiv__(self, other: _RealT) -> _RealT: ... @overload - def __floordiv__(self, other: Decimal) -> Decimal: - ... + def __floordiv__(self, other: Decimal) -> Decimal: ... @beartype def __floordiv__(self, other): @@ -858,12 +810,10 @@ def __floordiv__(self, other): return __floordiv__(self.val, other) @overload - def __rfloordiv__(self, other: _RealT) -> _RealT: # type: ignore [misc] - ... + def __rfloordiv__(self, other: _RealT) -> _RealT: ... @overload - def __rfloordiv__(self, other: Decimal) -> Decimal: - ... + def __rfloordiv__(self, other: Decimal) -> Decimal: ... @beartype def __rfloordiv__(self, other): @@ -873,12 +823,10 @@ def __rfloordiv__(self, other): return __floordiv__(other, self.val) @overload - def __mod__(self, other: _RealT) -> _RealT: - ... + def __mod__(self, other: _RealT) -> _RealT: ... @overload - def __mod__(self, other: Decimal) -> Decimal: - ... + def __mod__(self, other: Decimal) -> Decimal: ... @beartype def __mod__(self, other): @@ -888,12 +836,10 @@ def __mod__(self, other): return __mod__(self.val, other) @overload - def __rmod__(self, other: _RealT) -> _RealT: - ... + def __rmod__(self, other: _RealT) -> _RealT: ... @overload - def __rmod__(self, other: Decimal) -> Decimal: - ... + def __rmod__(self, other: Decimal) -> Decimal: ... @beartype def __rmod__(self, other): @@ -903,12 +849,10 @@ def __rmod__(self, other): return __mod__(other, self.val) @overload - def __pow__(self, other: _RealT) -> _RealT: - ... + def __pow__(self, other: _RealT) -> _RealT: ... @overload - def __pow__(self, other: Decimal) -> Decimal: - ... + def __pow__(self, other: Decimal) -> Decimal: ... @beartype def __pow__(self, other): @@ -920,12 +864,10 @@ def __pow__(self, other): return val @overload - def __rpow__(self, other: _RealT) -> _RealT: - ... + def __rpow__(self, other: _RealT) -> _RealT: ... @overload - def __rpow__(self, other: Decimal) -> Decimal: - ... + def __rpow__(self, other: Decimal) -> Decimal: ... @beartype def __rpow__(self, other): @@ -953,12 +895,10 @@ def __float__(self) -> float: return self.val @overload - def __round__(self) -> int: - ... + def __round__(self) -> int: ... @overload - def __round__(self, ndigits: _IntegralT) -> float: - ... + def __round__(self, ndigits: _IntegralT) -> float: ... @beartype def __round__(self, ndigits: Optional[_IntegralT] = None) -> Union[int, float]: @@ -993,7 +933,7 @@ class WangernumbRegistered(Wangernumb): assert issubclass(WangernumbRegistered, Real) -class WangernumbDerived(Wangernumb, Real): # type: ignore [misc] +class WangernumbDerived(Wangernumb, Real): __slots__: Any = () diff --git a/tests/test_integral_like.py b/tests/test_integral_like.py index 506886d..9f29b3c 100644 --- a/tests/test_integral_like.py +++ b/tests/test_integral_like.py @@ -129,14 +129,14 @@ def test_integral_like_numpy() -> None: pytest.importorskip("numpy", reason="requires numpy") import numpy - uint8_val: IntegralLike = numpy.uint8(2) # type: ignore [assignment] - uint16_val: IntegralLike = numpy.uint16(273) # type: ignore [assignment] - uint32_val: IntegralLike = numpy.uint32(273) # type: ignore [assignment] - uint64_val: IntegralLike = numpy.uint64(273) # type: ignore [assignment] - int8_val: IntegralLike = numpy.int8(-2) # type: ignore [assignment] - int16_val: IntegralLike = numpy.int16(-273) # type: ignore [assignment] - int32_val: IntegralLike = numpy.int32(-273) # type: ignore [assignment] - int64_val: IntegralLike = numpy.int64(-273) # type: ignore [assignment] + uint8_val: IntegralLike = numpy.uint8(2) + uint16_val: IntegralLike = numpy.uint16(273) + uint32_val: IntegralLike = numpy.uint32(273) + uint64_val: IntegralLike = numpy.uint64(273) + int8_val: IntegralLike = numpy.int8(-2) + int16_val: IntegralLike = numpy.int16(-273) + int32_val: IntegralLike = numpy.int32(-273) + int64_val: IntegralLike = numpy.int64(-273) for good_val in ( uint8_val, @@ -167,13 +167,13 @@ def test_integral_like_numpy() -> None: assert good_val & 0 == 0, f"{good_val!r}" assert good_val | 0 == good_val, f"{good_val!r}" - float16_val: IntegralLike = numpy.float16(-1.8) # type: ignore [assignment] - float32_val: IntegralLike = numpy.float32(-273.15) # type: ignore [assignment] - float64_val: IntegralLike = numpy.float64(-273.15) # type: ignore [assignment] - float128_val: IntegralLike = numpy.float128(-273.15) # type: ignore [assignment] - csingle_val: IntegralLike = numpy.csingle(-273.15) # type: ignore [assignment] - cdouble_val: IntegralLike = numpy.cdouble(-273.15) # type: ignore [assignment] - clongdouble_val: IntegralLike = numpy.clongdouble(-273.15) # type: ignore [assignment] + float16_val: IntegralLike = numpy.float16(-1.8) + float32_val: IntegralLike = numpy.float32(-273.15) + float64_val: IntegralLike = numpy.float64(-273.15) + float128_val: IntegralLike = numpy.float128(-273.15) + csingle_val: IntegralLike = numpy.csingle(-273.15) + cdouble_val: IntegralLike = numpy.cdouble(-273.15) + clongdouble_val: IntegralLike = numpy.clongdouble(-273.15) for bad_val in ( float16_val, @@ -242,7 +242,7 @@ def test_integral_like_sympy() -> None: assert good_val & 0 == 0, f"{good_val!r}" assert good_val | 0 == good_val, f"{good_val!r}" - float_val: IntegralLike = sympy.Float(-273.15) # type: ignore [assignment] + float_val: IntegralLike = sympy.Float(-273.15) # TODO(posita): These should not validate rational_val: IntegralLike = sympy.Rational(-27315, 100) sym_val: IntegralLike = sympy.symbols("x")