@@ -2620,8 +2620,6 @@ _NBit1 = TypeVar("_NBit1", bound=NBitBase)
2620
2620
_NBit2 = TypeVar ("_NBit2" , bound = NBitBase )
2621
2621
2622
2622
class generic (_ArrayOrScalarCommon ):
2623
- @abstractmethod
2624
- def __init__ (self , * args : Any , ** kwargs : Any ) -> None : ...
2625
2623
# TODO: use `tuple[()]` as shape type once covariant (#26081)
2626
2624
@overload
2627
2625
def __array__ (self : _ScalarType , dtype : None = ..., / ) -> NDArray [_ScalarType ]: ...
@@ -2848,12 +2846,41 @@ class bool(generic):
2848
2846
2849
2847
bool_ : TypeAlias = bool
2850
2848
2849
+ _StringType = TypeVar ("_StringType" , bound = str | bytes )
2850
+ _StringType = TypeVar ("_StringType" , bound = str | bytes )
2851
+ _ShapeType = TypeVar ("_ShapeType" , bound = Any )
2852
+ _ObjectType = TypeVar ("_ObjectType" , bound = object )
2853
+
2854
+ # A sequence-like interface like `collections.abc.Sequence`, but without the
2855
+ # irrelevant methods.
2856
+ class _SimpleSequence (Protocol ):
2857
+ def __len__ (self , / ) -> int : ...
2858
+ def __getitem__ (self , index : int , / ) -> Any : ...
2859
+
2860
+ # The `object_` constructor returns the passed object, so instances with type
2861
+ # `object_` cannot exists (at runtime).
2851
2862
class object_ (generic ):
2852
- def __init__ (self , value : object = ..., / ) -> None : ...
2863
+ @overload
2864
+ def __new__ (cls , nothing_to_see_here : None = ..., / ) -> None : ...
2865
+ @overload
2866
+ def __new__ (cls , stringy : _StringType , / ) -> _StringType : ...
2867
+ @overload
2868
+ def __new__ (
2869
+ cls ,
2870
+ array : ndarray [_ShapeType , Any ], / ,
2871
+ ) -> ndarray [_ShapeType , dtype [object_ ]]: ...
2872
+ @overload
2873
+ def __new__ (cls , sequence : _SimpleSequence , / ) -> NDArray [object_ ]: ...
2874
+ @overload
2875
+ def __new__ (cls , value : _ObjectType , / ) -> _ObjectType : ...
2876
+ # catch-all
2877
+ @overload
2878
+ def __new__ (cls , value : Any = ..., / ) -> object | NDArray [object_ ]: ...
2879
+
2853
2880
@property
2854
- def real (self : _ArraySelf ) -> _ArraySelf : ...
2881
+ def real (self ) -> object_ : ...
2855
2882
@property
2856
- def imag (self : _ArraySelf ) -> _ArraySelf : ...
2883
+ def imag (self ) -> object_ : ...
2857
2884
# The 3 protocols below may or may not raise,
2858
2885
# depending on the underlying object
2859
2886
def __int__ (self ) -> int : ...
0 commit comments