@@ -2620,8 +2620,6 @@ _NBit1 = TypeVar("_NBit1", bound=NBitBase)
26202620_NBit2 = TypeVar ("_NBit2" , bound = NBitBase )
26212621
26222622class generic (_ArrayOrScalarCommon ):
2623- @abstractmethod
2624- def __init__ (self , * args : Any , ** kwargs : Any ) -> None : ...
26252623 # TODO: use `tuple[()]` as shape type once covariant (#26081)
26262624 @overload
26272625 def __array__ (self : _ScalarType , dtype : None = ..., / ) -> NDArray [_ScalarType ]: ...
@@ -2848,12 +2846,41 @@ class bool(generic):
28482846
28492847bool_ : TypeAlias = bool
28502848
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).
28512862class 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+
28532880 @property
2854- def real (self : _ArraySelf ) -> _ArraySelf : ...
2881+ def real (self ) -> object_ : ...
28552882 @property
2856- def imag (self : _ArraySelf ) -> _ArraySelf : ...
2883+ def imag (self ) -> object_ : ...
28572884 # The 3 protocols below may or may not raise,
28582885 # depending on the underlying object
28592886 def __int__ (self ) -> int : ...
0 commit comments