Repository: numpy/numpy
File: numpy/__init__.pyi (Python)

Code before:

    # Keep `dtype` at the bottom to avoid name conflicts with `np.dtype`
    @property
    def dtype(self) -> _DTypeT_co: ...

# NOTE: while `np.generic` is not technically an instance of `ABCMeta`,
# the `@abstractmethod` decorator is herein used to (forcefully) deny
# the creation of `np.generic` instances.
# The `# type: ignore` comments are necessary to silence mypy errors regarding
# the missing `ABCMeta` metaclass.
# See https://github.com/numpy/numpy-stubs/pull/80 for more details.
class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]):
    @abstractmethod
    def __new__(cls, /, *args: Any, **kwargs: Any) -> Self: ...

    if sys.version_info >= (3, 12):
        def __buffer__(self, flags: int, /) -> memoryview: ...

    @overload
    def __array__(self, dtype: None = None, /) -> ndarray[tuple[()], dtype[Self]]: ...
    @overload
    def __array__(self, dtype: _DTypeT, /) -> ndarray[tuple[()], _DTypeT]: ...

    #
    @overload
    def __getitem__(self, key: None, /) -> ndarray[tuple[L[1]], dtype[Self]]: ...

    #
    @overload
    def __array_wrap__(
        self,
        array: ndarray[_ShapeT, _DTypeT],
        context: tuple[ufunc, tuple[object, ...], int] | None,
        return_scalar: L[False],
        /,
    ) -> ndarray[_ShapeT, _DTypeT]: ...
    @overload
    def __array_wrap__(
        self,
        array: ndarray[tuple[()], dtype[_ScalarT]],
        context: tuple[ufunc, tuple[object, ...], int] | None = None,
        return_scalar: L[True] = True,
        /,
    ) -> _ScalarT: ...
    @overload
    def __array_wrap__(
        self,
        array: ndarray[_Shape1T, _DTypeT],
        context: tuple[ufunc, tuple[object, ...], int] | None = None,
        return_scalar: L[True] = True,
        /,

Review comment (suggestion):
Literal shape axes can (unfortunately) be problematic in practice (there are still some places in the stubs where it's used, but I plan to remove those soon), so it's better to try and stick to boring `int`'s.

```suggestion
    def __getitem__(self, key: None, /) -> ndarray[tuple[int], dtype[Self]]: ...
```

Code after:

    # Keep `dtype` at the bottom to avoid name conflicts with `np.dtype`
    @property
    def dtype(self) -> _DTypeT_co: ...

# NOTE: while `np.generic` is not technically an instance of `ABCMeta`,
# the `@abstractmethod` decorator is herein used to (forcefully) deny
# the creation of `np.generic` instances.
# The `# type: ignore` comments are necessary to silence mypy errors regarding
# the missing `ABCMeta` metaclass.
# See https://github.com/numpy/numpy-stubs/pull/80 for more details.
class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]):
    @abstractmethod
    def __new__(cls, /, *args: Any, **kwargs: Any) -> Self: ...

    if sys.version_info >= (3, 12):
        def __buffer__(self, flags: int, /) -> memoryview: ...

    @overload
    def __array__(self, dtype: None = None, /) -> ndarray[tuple[()], dtype[Self]]: ...
    @overload
    def __array__(self, dtype: _DTypeT, /) -> ndarray[tuple[()], _DTypeT]: ...

    #
    @overload
    def __getitem__(self, key: tuple[()], /) -> Self: ...
    @overload
    def __getitem__(
        self, key: EllipsisType | tuple[EllipsisType], /
    ) -> ndarray[tuple[()], dtype[Self]]: ...
    @overload
    def __getitem__(
        self, key: None | tuple[None], /
    ) -> ndarray[tuple[int], dtype[Self]]: ...
    @overload
    def __getitem__(
        self, key: tuple[None, None], /
    ) -> ndarray[tuple[int, int], dtype[Self]]: ...
    @overload
    def __getitem__(
        self, key: tuple[None, None, None], /
    ) -> ndarray[tuple[int, int, int], dtype[Self]]: ...
    @overload  # Limited support for (None,) * N > 3
    def __getitem__(self, key: tuple[None, ...], /) -> NDArray[Self]: ...

    #
    @overload
    def __array_wrap__(
        self,
        array: ndarray[_ShapeT, _DTypeT],
        context: tuple[ufunc, tuple[object, ...], int] | None,