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
3 changes: 0 additions & 3 deletions .mypyignore-todo
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,6 @@ numpy._pyinstaller.hook-numpy
numpy.compat
numpy.compat.py3k

numpy.core.__all__
numpy.core._dtype
numpy.core._dtype_ctypes
numpy.core.arrayprint
numpy.core.defchararray
numpy.core.einsumfunc
Expand Down
57 changes: 57 additions & 0 deletions src/numpy-stubs/_core/_dtype.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from typing import Any, Final, Literal as L, TypeAlias, TypedDict, overload, type_check_only
from typing_extensions import ReadOnly, TypeVar

import numpy as np

###

_T = TypeVar("_T")

_Kind: TypeAlias = L["u", "i", "c", "f", "b", "V", "O", "M", "m", "S", "U"]
_Name: TypeAlias = L["uint", "int", "complex", "float", "bool", "void", "object", "datetime", "timedelta", "bytes", "str"]

@type_check_only
class _KindToStemType(TypedDict):
u: ReadOnly[L["uint"]]
i: ReadOnly[L["int"]]
c: ReadOnly[L["complex"]]
f: ReadOnly[L["float"]]
b: ReadOnly[L["bool"]]
V: ReadOnly[L["void"]]
O: ReadOnly[L["object"]]
M: ReadOnly[L["datetime"]]
m: ReadOnly[L["timedelta"]]
S: ReadOnly[L["bytes"]]
U: ReadOnly[L["str"]]

###

_kind_to_stem: Final[_KindToStemType] = ...

#
def _kind_name(dtype: np.dtype[Any]) -> _Name: ...
def __str__(dtype: np.dtype[Any]) -> str: ...
def __repr__(dtype: np.dtype[Any]) -> str: ...

#
def _isunsized(dtype: np.dtype[Any]) -> bool: ...
def _is_packed(dtype: np.dtype[Any]) -> bool: ...
def _name_includes_bit_suffix(dtype: np.dtype[Any]) -> bool: ...

#
def _construction_repr(dtype: np.dtype[Any], include_align: bool = False, short: bool = False) -> str: ...
def _scalar_str(dtype: np.dtype[Any], short: bool) -> str: ...
def _byte_order_str(dtype: np.dtype[Any]) -> str: ...
def _datetime_metadata_str(dtype: np.dtype[Any]) -> str: ...
def _struct_dict_str(dtype: np.dtype[Any], includealignedflag: bool) -> str: ...
def _struct_list_str(dtype: np.dtype[Any]) -> str: ...
def _struct_str(dtype: np.dtype[Any], include_align: bool) -> str: ...
def _subarray_str(dtype: np.dtype[Any]) -> str: ...
def _name_get(dtype: np.dtype[Any]) -> str: ...

#
@overload
def _unpack_field(dtype: np.dtype[Any], offset: int, title: _T) -> tuple[np.dtype[Any], int, _T]: ...
@overload
def _unpack_field(dtype: np.dtype[Any], offset: int, title: None = None) -> tuple[np.dtype[Any], int, None]: ...
def _aligned_offset(offset: int, alignment: int) -> int: ...
83 changes: 83 additions & 0 deletions src/numpy-stubs/_core/_dtype_ctypes.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import _ctypes
import ctypes as ct
from typing import Any, overload

import numpy as np

#
@overload
def dtype_from_ctypes_type(t: type[_ctypes.Array[Any] | _ctypes.Structure]) -> np.dtype[np.void]: ...
@overload
def dtype_from_ctypes_type(t: type[ct.c_bool]) -> np.dtype[np.bool]: ...
@overload
def dtype_from_ctypes_type(t: type[ct.c_int8 | ct.c_byte]) -> np.dtype[np.int8]: ...
@overload
def dtype_from_ctypes_type(t: type[ct.c_uint8 | ct.c_ubyte]) -> np.dtype[np.uint8]: ...
@overload
def dtype_from_ctypes_type(t: type[ct.c_int16 | ct.c_short]) -> np.dtype[np.int16]: ...
@overload
def dtype_from_ctypes_type(t: type[ct.c_uint16 | ct.c_ushort]) -> np.dtype[np.uint16]: ...
@overload
def dtype_from_ctypes_type(t: type[ct.c_int32 | ct.c_int]) -> np.dtype[np.int32]: ...
@overload
def dtype_from_ctypes_type(t: type[ct.c_uint32 | ct.c_uint]) -> np.dtype[np.uint32]: ...
@overload
def dtype_from_ctypes_type(t: type[ct.c_ssize_t | ct.c_long]) -> np.dtype[np.int32 | np.int64]: ...
@overload
def dtype_from_ctypes_type(t: type[ct.c_size_t | ct.c_ulong]) -> np.dtype[np.uint32 | np.uint64]: ...
@overload
def dtype_from_ctypes_type(t: type[ct.c_int64 | ct.c_longlong]) -> np.dtype[np.int64]: ...
@overload
def dtype_from_ctypes_type(t: type[ct.c_uint64 | ct.c_ulonglong]) -> np.dtype[np.uint64]: ...
@overload
def dtype_from_ctypes_type(t: type[ct.c_float]) -> np.dtype[np.float32]: ...
@overload
def dtype_from_ctypes_type(t: type[ct.c_double]) -> np.dtype[np.float64]: ...
@overload
def dtype_from_ctypes_type(t: type[ct.c_longdouble]) -> np.dtype[np.longdouble]: ...
@overload
def dtype_from_ctypes_type(t: type[ct.c_char]) -> np.dtype[np.bytes_]: ...
@overload
def dtype_from_ctypes_type(t: type[ct.py_object[Any]]) -> np.dtype[np.object_]: ...

# NOTE: the complex ctypes on python>=3.14 are not yet supported at runtim, see
# https://github.com/numpy/numpy/issues/28360

#
def _from_ctypes_array(t: type[_ctypes.Array[Any]]) -> np.dtype[np.void]: ...
def _from_ctypes_structure(t: type[_ctypes.Structure]) -> np.dtype[np.void]: ...
def _from_ctypes_union(t: type[_ctypes.Union]) -> np.dtype[np.void]: ...

# keep in sync with `dtype_from_ctypes_type` (minus the first overload)
@overload
def _from_ctypes_scalar(t: type[ct.c_bool]) -> np.dtype[np.bool]: ...
@overload
def _from_ctypes_scalar(t: type[ct.c_int8 | ct.c_byte]) -> np.dtype[np.int8]: ...
@overload
def _from_ctypes_scalar(t: type[ct.c_uint8 | ct.c_ubyte]) -> np.dtype[np.uint8]: ...
@overload
def _from_ctypes_scalar(t: type[ct.c_int16 | ct.c_short]) -> np.dtype[np.int16]: ...
@overload
def _from_ctypes_scalar(t: type[ct.c_uint16 | ct.c_ushort]) -> np.dtype[np.uint16]: ...
@overload
def _from_ctypes_scalar(t: type[ct.c_int32 | ct.c_int]) -> np.dtype[np.int32]: ...
@overload
def _from_ctypes_scalar(t: type[ct.c_uint32 | ct.c_uint]) -> np.dtype[np.uint32]: ...
@overload
def _from_ctypes_scalar(t: type[ct.c_ssize_t | ct.c_long]) -> np.dtype[np.int32 | np.int64]: ...
@overload
def _from_ctypes_scalar(t: type[ct.c_size_t | ct.c_ulong]) -> np.dtype[np.uint32 | np.uint64]: ...
@overload
def _from_ctypes_scalar(t: type[ct.c_int64 | ct.c_longlong]) -> np.dtype[np.int64]: ...
@overload
def _from_ctypes_scalar(t: type[ct.c_uint64 | ct.c_ulonglong]) -> np.dtype[np.uint64]: ...
@overload
def _from_ctypes_scalar(t: type[ct.c_float]) -> np.dtype[np.float32]: ...
@overload
def _from_ctypes_scalar(t: type[ct.c_double]) -> np.dtype[np.float64]: ...
@overload
def _from_ctypes_scalar(t: type[ct.c_longdouble]) -> np.dtype[np.longdouble]: ...
@overload
def _from_ctypes_scalar(t: type[ct.c_char]) -> np.dtype[np.bytes_]: ...
@overload
def _from_ctypes_scalar(t: type[ct.py_object[Any]]) -> np.dtype[np.object_]: ...
8 changes: 4 additions & 4 deletions src/numpy-stubs/core/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from numpy import _core as _core # noqa: ICN003
from numpy._core import (
# _dtype,
# _dtype_ctypes,
_dtype,
_dtype_ctypes,
_internal,
_multiarray_umath,
arrayprint,
Expand All @@ -23,8 +23,8 @@ from numpy._core import (
)

__all__ = [
# "_dtype",
# "_dtype_ctypes",
"_dtype",
"_dtype_ctypes",
"_internal",
"_multiarray_umath",
"arrayprint",
Expand Down
Empty file added src/numpy-stubs/core/_dtype.pyi
Empty file.
Empty file.