Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
521 changes: 287 additions & 234 deletions src/numpy-stubs/__init__.pyi

Large diffs are not rendered by default.

25 changes: 4 additions & 21 deletions src/numpy-stubs/_core/getlimits.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,21 @@ from typing_extensions import Self, TypeVar

import numpy as np
from _numtype import inexact32, inexact64, inexact64l
from numpy._typing import _96Bit, _128Bit, _DTypeLike
from numpy._typing import _DTypeLike
from numpy._typing._char_codes import (
_CLongDoubleCodes,
_CLongDoubleCodes as _CFloat64LCodes,
_Complex64Codes,
_Complex128Codes,
_Complex192Codes,
_Complex256Codes,
_Float16Codes,
_Float32Codes,
_Float64Codes,
_Float96Codes,
_Float128Codes,
_Int8Codes,
_Int16Codes,
_Int32Codes,
_Int64Codes,
_IntPCodes,
_LongCodes,
_LongDoubleCodes,
_LongDoubleCodes as _Float64LCodes,
_UInt8Codes,
_UInt16Codes,
_UInt32Codes,
Expand Down Expand Up @@ -120,20 +116,7 @@ class finfo(Generic[_FloatingT_co]):
@overload
def __new__(cls, dtype: inexact64 | _DTypeLike[inexact64] | _Float64Codes | _Complex128Codes) -> finfo[np.float64]: ...
@overload
def __new__(
cls,
dtype: np.inexact[_96Bit] | _DTypeLike[np.inexact[_96Bit]] | _Float96Codes | _Complex192Codes,
) -> finfo[np.float96]: ...
@overload
def __new__(
cls,
dtype: np.inexact[_128Bit] | _DTypeLike[np.inexact[_128Bit]] | _Float128Codes | _Complex256Codes,
) -> finfo[np.float128]: ...
@overload
def __new__(
cls,
dtype: inexact64l | _DTypeLike[inexact64l] | _LongDoubleCodes | _CLongDoubleCodes,
) -> finfo[np.float96 | np.float128]: ...
def __new__(cls, dtype: inexact64l | _DTypeLike[inexact64l] | _Float64LCodes | _CFloat64LCodes) -> finfo[np.longdouble]: ...

#
@classmethod
Expand Down
16 changes: 1 addition & 15 deletions src/numpy-stubs/_typing/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,7 @@ from ._dtype_like import (
_SupportsDType as _SupportsDType,
_VoidDTypeLike as _VoidDTypeLike,
)
from ._nbit import (
_NBitIntP as _NBitIntP,
_NBitLong as _NBitLong,
_NBitLongDouble as _NBitLongDouble,
_NBitLongLong as _NBitLongLong,
)
from ._nbit_base import (
NBitBase as NBitBase,
_8Bit as _8Bit,
_16Bit as _16Bit,
_32Bit as _32Bit,
_64Bit as _64Bit,
_96Bit as _96Bit,
_128Bit as _128Bit,
)
from ._nbit_base import NBitBase as NBitBase
from ._nested_sequence import _NestedSequence as _NestedSequence
from ._scalars import (
_BoolLike_co as _BoolLike_co,
Expand Down
5 changes: 2 additions & 3 deletions src/numpy-stubs/_typing/_array_like.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ from typing_extensions import Buffer, TypeVar
import numpy as np
from numpy.dtypes import StringDType

from ._nbit_base import _64Bit
from ._nested_sequence import _NestedSequence
from ._shape import _Shape

Expand Down Expand Up @@ -67,8 +66,8 @@ _ArrayLikeBytes_co: TypeAlias = _DualArrayLike[np.dtype[np.bytes_], bytes]
_ArrayLikeString_co: TypeAlias = _DualArrayLike[StringDType, str]
_ArrayLikeAnyString_co: TypeAlias = _DualArrayLike[StringDType | np.dtype[np.character], bytes | str]

__Float64_co: TypeAlias = np.floating[_64Bit] | np.float32 | np.float16 | np.integer | np.bool
__Complex128_co: TypeAlias = np.complexfloating[_64Bit] | np.complex64 | __Float64_co
__Float64_co: TypeAlias = np.float64 | np.float32 | np.float16 | np.integer | np.bool
__Complex128_co: TypeAlias = np.complex128 | np.complex64 | __Float64_co
_ArrayLikeFloat64_co: TypeAlias = _DualArrayLike[np.dtype[__Float64_co], float]
_ArrayLikeComplex128_co: TypeAlias = _DualArrayLike[np.dtype[__Complex128_co], complex]

Expand Down
25 changes: 0 additions & 25 deletions src/numpy-stubs/_typing/_nbit.pyi
Original file line number Diff line number Diff line change
@@ -1,25 +0,0 @@
from typing import TypeAlias
from typing_extensions import Never

from ._nbit_base import _32Bit, _64Bit, _96Bit, _128Bit

###
# TODO(jorenham): Stop using these:
# https://github.com/numpy/numtype/issues/136

_NBitIntP: TypeAlias = _32Bit | _64Bit
_NBitLong: TypeAlias = _32Bit | _64Bit
_NBitLongLong: TypeAlias = _64Bit
_NBitLongDouble: TypeAlias = _96Bit | _128Bit

###
# unused legacy aliases

_NBitByte: TypeAlias = Never
_NBitShort: TypeAlias = Never
_NBitIntC: TypeAlias = Never
_NBitInt: TypeAlias = Never

_NBitHalf: TypeAlias = Never
_NBitSingle: TypeAlias = Never
_NBitDouble: TypeAlias = Never
15 changes: 0 additions & 15 deletions src/numpy-stubs/_typing/_nbit_base.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# mypy: disable-error-code="misc"
from typing import final, type_check_only
from typing_extensions import Never

# exported as numpy.typing.NBitBase

Expand Down Expand Up @@ -28,17 +27,3 @@ class _16(_32_64): ...

@type_check_only
class _8(_16): ...

###
# legacy `numpy._typing` runtime definitions

_128Bit = _64L
_96Bit = _64L
_64Bit = _64
_32Bit = _32
_16Bit = _16
_8Bit = _8

# non-existant
_256Bit = Never
_80Bit = Never
24 changes: 12 additions & 12 deletions src/numpy-stubs/ctypeslib.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -150,21 +150,21 @@ def as_ctypes(obj: np.int64) -> ct.c_int64: ...
@overload
def as_ctypes(obj: NDArray[np.int64]) -> ct.Array[ct.c_int64]: ...
@overload # uint8 / ubyte
def as_ctypes(obj: np.uint8) -> ct.c_uint8: ... # type: ignore[overload-overlap]
def as_ctypes(obj: np.uint8) -> ct.c_uint8: ...
@overload
def as_ctypes(obj: NDArray[np.uint8]) -> ct.Array[ct.c_uint8]: ... # type: ignore[overload-overlap]
def as_ctypes(obj: NDArray[np.uint8]) -> ct.Array[ct.c_uint8]: ...
@overload # uint16 / ushort
def as_ctypes(obj: np.uint16) -> ct.c_uint16: ... # type: ignore[overload-overlap]
def as_ctypes(obj: np.uint16) -> ct.c_uint16: ...
@overload
def as_ctypes(obj: NDArray[np.uint16]) -> ct.Array[ct.c_uint16]: ... # type: ignore[overload-overlap]
def as_ctypes(obj: NDArray[np.uint16]) -> ct.Array[ct.c_uint16]: ...
@overload # uint32 / uint
def as_ctypes(obj: np.uint32) -> ct.c_uint32: ... # type: ignore[overload-overlap]
def as_ctypes(obj: np.uint32) -> ct.c_uint32: ...
@overload
def as_ctypes(obj: NDArray[np.uint32]) -> ct.Array[ct.c_uint32]: ... # type: ignore[overload-overlap]
def as_ctypes(obj: NDArray[np.uint32]) -> ct.Array[ct.c_uint32]: ...
@overload # ulong
def as_ctypes(obj: np.ulong) -> ct.c_ulong: ... # type: ignore[overload-overlap]
def as_ctypes(obj: np.ulong) -> ct.c_ulong: ...
@overload
def as_ctypes(obj: NDArray[np.ulong]) -> ct.Array[ct.c_ulong]: ... # type: ignore[overload-overlap]
def as_ctypes(obj: NDArray[np.ulong]) -> ct.Array[ct.c_ulong]: ...
@overload # uint64 / ulonglong
def as_ctypes(obj: np.uint64) -> ct.c_uint64: ...
@overload
Expand Down Expand Up @@ -198,13 +198,13 @@ def as_ctypes_type(dtype: _DTypeLike[np.int64] | type[ct.c_int64] | _Int64Codes)
@overload
def as_ctypes_type(dtype: type[JustInt | ct.c_ssize_t] | _IntPCodes) -> type[ct.c_ssize_t]: ...
@overload
def as_ctypes_type(dtype: _DTypeLike[np.uint8] | type[ct.c_uint8 | ct.c_ubyte] | _UInt8Codes) -> type[ct.c_uint8]: ... # type: ignore[overload-overlap]
def as_ctypes_type(dtype: _DTypeLike[np.uint8] | type[ct.c_uint8 | ct.c_ubyte] | _UInt8Codes) -> type[ct.c_uint8]: ...
@overload
def as_ctypes_type(dtype: _DTypeLike[np.uint16] | type[ct.c_uint16 | ct.c_ushort] | _UInt16Codes) -> type[ct.c_uint16]: ... # type: ignore[overload-overlap]
def as_ctypes_type(dtype: _DTypeLike[np.uint16] | type[ct.c_uint16 | ct.c_ushort] | _UInt16Codes) -> type[ct.c_uint16]: ...
@overload
def as_ctypes_type(dtype: _DTypeLike[np.uint32] | type[ct.c_uint32 | ct.c_uint] | _UInt32Codes) -> type[ct.c_uint32]: ... # type: ignore[overload-overlap]
def as_ctypes_type(dtype: _DTypeLike[np.uint32] | type[ct.c_uint32 | ct.c_uint] | _UInt32Codes) -> type[ct.c_uint32]: ...
@overload
def as_ctypes_type(dtype: _DTypeLike[np.ulong] | type[ct.c_ulong] | _ULongCodes) -> type[ct.c_ulong]: ... # type: ignore[overload-overlap]
def as_ctypes_type(dtype: _DTypeLike[np.ulong] | type[ct.c_ulong] | _ULongCodes) -> type[ct.c_ulong]: ...
@overload
def as_ctypes_type(dtype: _DTypeLike[np.uint64] | type[ct.c_uint64] | _UInt64Codes) -> type[ct.c_uint64]: ...
@overload
Expand Down
4 changes: 2 additions & 2 deletions src/numtype/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""A superset of `numpy.typing`. Will be expanded in the future."""

from numpy.typing import ArrayLike, DTypeLike, NBitBase, NDArray # noqa: ICN003
from numpy.typing import ArrayLike, DTypeLike, NDArray # noqa: ICN003

from .version import __version__

__all__ = ["ArrayLike", "DTypeLike", "NBitBase", "NDArray", "__version__"]
__all__ = ["ArrayLike", "DTypeLike", "NDArray", "__version__"]
6 changes: 4 additions & 2 deletions test/runtime/test_numtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
import numpy.typing as npt
import numtype as nt

NPT_DIR = tuple(k for k in npt.__all__ if k != "NBitBase")


def test_superset() -> None:
assert set(nt.__all__) > set(npt.__all__)
assert set(nt.__all__) > set(NPT_DIR)


@pytest.mark.parametrize("name", npt.__all__)
@pytest.mark.parametrize("name", NPT_DIR)
def test_reexport(name: str) -> None:
assert getattr(nt, name) is getattr(npt, name)

Expand Down
20 changes: 0 additions & 20 deletions test/static/accept/nbit_base_example.pyi

This file was deleted.

3 changes: 0 additions & 3 deletions tool/allowlists/common-todo.txt

This file was deleted.

1 change: 0 additions & 1 deletion tool/stubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@

ALLOWLISTS = [
"common.txt",
"common-todo.txt",
("ge" if sys.version_info >= (3, 12) else "lt") + "-py312.txt",
]

Expand Down