From f9d06a26c0cd409f81b032e465343fce774d73ec Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Thu, 28 Nov 2024 00:16:47 -0600 Subject: [PATCH 1/2] Add RealNumber --- pymbolic/__init__.py | 2 ++ pymbolic/typing.py | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/pymbolic/__init__.py b/pymbolic/__init__.py index ca17dca..b32e3ba 100644 --- a/pymbolic/__init__.py +++ b/pymbolic/__init__.py @@ -66,6 +66,7 @@ Expression, Expression as _TypingExpression, Number, + RealNumber, Scalar, ) from pymbolic.version import VERSION_TEXT as __version__ # noqa @@ -77,6 +78,7 @@ "Expression", "ExpressionNode", "Number", + "RealNumber", "Scalar", "Variable", "compile", diff --git a/pymbolic/typing.py b/pymbolic/typing.py index d1bf82e..8bd3f67 100644 --- a/pymbolic/typing.py +++ b/pymbolic/typing.py @@ -4,9 +4,14 @@ .. currentmodule:: pymbolic -.. autoclass:: Bool -.. autoclass:: Number -.. autoclass:: Scalar +.. autodata:: Bool +.. autodata:: RealNumber + + Mainly distinguished from :data:`Number` by having a total ordering, i.e. + not including the complex numbers. + +.. autodata:: Number +.. autodata:: Scalar .. autodata:: ArithmeticExpression A narrower type alias than :class:`~pymbolic.typing.Expression` that is returned @@ -88,8 +93,9 @@ if TYPE_CHECKING: # Yes, type-checking pymbolic will require numpy. That's OK. import numpy as np - Bool = bool | np.bool_ + Bool: TypeAlias = bool | np.bool_ Integer: TypeAlias = int | np.integer + RealNumber: TypeAlias = Integer | float | np.floating InexactNumber: TypeAlias = _StdlibInexactNumberT | np.inexact else: try: @@ -97,10 +103,12 @@ except ImportError: Bool = bool Integer: TypeAlias = int + RealNumber: TypeAlias = Integer | float InexactNumber: TypeAlias = _StdlibInexactNumberT else: Bool = bool | np.bool_ Integer: TypeAlias = int | np.integer + RealNumber: TypeAlias = Integer | float | np.floating InexactNumber: TypeAlias = _StdlibInexactNumberT | np.inexact From 21e1aeab8d112d784ce23752f4097e6962710d3c Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Thu, 28 Nov 2024 00:16:55 -0600 Subject: [PATCH 2/2] Type _classproperty --- pymbolic/primitives.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pymbolic/primitives.py b/pymbolic/primitives.py index d42427c..caf0dbf 100644 --- a/pymbolic/primitives.py +++ b/pymbolic/primitives.py @@ -368,7 +368,8 @@ def disable_subscript_by_getitem(): # https://stackoverflow.com/a/13624858 class _classproperty(property): # noqa: N801 - def __get__(self, owner_self, owner_cls): + def __get__(self, owner_self: Any, owner_cls: type | None = None) -> Any: + assert self.fget is not None return self.fget(owner_cls)