@@ -4,8 +4,14 @@ import numpy as np
44from typing_extensions import Never , Self , override
55
66_Backend : TypeAlias = Literal ["sleef" , "longdouble" ]
7- _IntoQuad : TypeAlias = QuadPrecision | float | str
8- _CastsQuad : TypeAlias = _IntoQuad | np .floating [Any ] | np .integer [Any ] | np .bool_
7+ _IntoQuad : TypeAlias = (
8+ QuadPrecision
9+ | float
10+ | str
11+ | np .floating [Any ]
12+ | np .integer [Any ]
13+ | np .bool_
14+ ) # fmt: skip
915
1016@final
1117class QuadPrecDType (np .dtype [QuadPrecision ]): # type: ignore[misc, type-var] # pyright: ignore[reportGeneralTypeIssues, reportInvalidTypeArguments]
@@ -64,8 +70,15 @@ class QuadPrecDType(np.dtype[QuadPrecision]): # type: ignore[misc, type-var] #
6470 @override
6571 def __getitem__ (self , key : Never , / ) -> Self : ... # type: ignore[override]
6672
73+ # NOTE: Until `QuadPrecision` will become a subclass of `np.generic`, this class cannot
74+ # be considered "type-safe".
6775@final
68- class QuadPrecision : # NOTE: It doesn't inherit from `np.generic` which is type-unsafe
76+ class QuadPrecision :
77+ # NOTE: At runtime this constructor also accepts array-likes, for which it returns
78+ # `np.ndarray` instances with `dtype=QuadPrecDType()`.
79+ # But because of mypy limitations, it is currently impossible to annotate
80+ # constructors that do no return instances of their class (or a subclass thereof).
81+ # See https://github.com/python/mypy/issues/18343#issuecomment-2571784915
6982 def __new__ (cls , / , value : _IntoQuad , backend : _Backend = "sleef" ) -> Self : ...
7083
7184 # Rich comparison operators
@@ -80,16 +93,16 @@ class QuadPrecision: # NOTE: It doesn't inherit from `np.generic` which is type
8093 def __ge__ (self , other : _IntoQuad , / ) -> bool : ...
8194
8295 # Binary operators
83- def __add__ (self , other : _CastsQuad , / ) -> Self : ...
84- def __radd__ (self , other : _CastsQuad , / ) -> Self : ...
85- def __sub__ (self , other : _CastsQuad , / ) -> Self : ...
86- def __rsub__ (self , other : _CastsQuad , / ) -> Self : ...
87- def __mul__ (self , other : _CastsQuad , / ) -> Self : ...
88- def __rmul__ (self , other : _CastsQuad , / ) -> Self : ...
89- def __pow__ (self , other : _CastsQuad , mod : None = None , / ) -> Self : ...
90- def __rpow__ (self , other : _CastsQuad , mod : None = None , / ) -> Self : ...
91- def __truediv__ (self , other : _CastsQuad , / ) -> Self : ...
92- def __rtruediv__ (self , other : _CastsQuad , / ) -> Self : ...
96+ def __add__ (self , other : _IntoQuad , / ) -> Self : ...
97+ def __radd__ (self , other : _IntoQuad , / ) -> Self : ...
98+ def __sub__ (self , other : _IntoQuad , / ) -> Self : ...
99+ def __rsub__ (self , other : _IntoQuad , / ) -> Self : ...
100+ def __mul__ (self , other : _IntoQuad , / ) -> Self : ...
101+ def __rmul__ (self , other : _IntoQuad , / ) -> Self : ...
102+ def __pow__ (self , other : _IntoQuad , mod : None = None , / ) -> Self : ...
103+ def __rpow__ (self , other : _IntoQuad , mod : None = None , / ) -> Self : ...
104+ def __truediv__ (self , other : _IntoQuad , / ) -> Self : ...
105+ def __rtruediv__ (self , other : _IntoQuad , / ) -> Self : ...
93106
94107 # Unary operators
95108 def __neg__ (self , / ) -> Self : ...
0 commit comments