diff --git a/pymbolic/__init__.py b/pymbolic/__init__.py index ca17dcafe613f210c09d9afd7fa835e19ff1af2f..b32e3ba0a15f93b9daa924defff1b202afc4f89b 100644 --- a/pymbolic/__init__.py +++ b/pymbolic/__init__.py @@ -66,6 +66,7 @@ from .typing import ( Expression, Expression as _TypingExpression, Number, + RealNumber, Scalar, ) from pymbolic.version import VERSION_TEXT as __version__ # noqa @@ -77,6 +78,7 @@ __all__ = ( "Expression", "ExpressionNode", "Number", + "RealNumber", "Scalar", "Variable", "compile", diff --git a/pymbolic/typing.py b/pymbolic/typing.py index d1bf82e7522e0a6a9e8c4019d97758a4fa1e7968..8bd3f670d5a0a943ea7f03f76fac441dae5482c2 100644 --- a/pymbolic/typing.py +++ b/pymbolic/typing.py @@ -4,9 +4,14 @@ Typing helpers .. 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 @@ _StdlibInexactNumberT = float | complex 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 @@ else: 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