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
34 changes: 31 additions & 3 deletions src/numpy-stubs/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4272,6 +4272,9 @@ float32: TypeAlias = floating[_32Bit]

# either a C `double`, `float`, or `longdouble`
class float64(floating[_64Bit], float): # type: ignore[misc]
def __new__(cls, x: _ConvertibleToFloat | None = ..., /) -> Self: ...

#
@property
def itemsize(self) -> L[8]: ...
@property
Expand Down Expand Up @@ -4434,7 +4437,15 @@ class complexfloating(inexact[_NBit1, complex], Generic[_NBit1, _NBit2]):
def imag(self) -> floating[_NBit2]: ...

#
def __init__(self, value: _ConvertibleToComplex | None = ..., /) -> None: ...
@overload
def __init__(
self,
real: complex | SupportsComplex | SupportsFloat | SupportsIndex = ...,
imag: complex | SupportsFloat | SupportsIndex = ...,
/,
) -> None: ...
@overload
def __init__(self, real: _ConvertibleToComplex | None = ..., /) -> None: ...

# NOTE: `__complex__` is technically defined in the concrete subtypes
def __complex__(self, /) -> complex: ...
Expand Down Expand Up @@ -4530,6 +4541,17 @@ class complexfloating(inexact[_NBit1, complex], Generic[_NBit1, _NBit2]):
def __rpow__(self, other: number[_NBit], /) -> complexfloating[_NBit1, _NBit2] | complexfloating[_NBit]: ...

class complex128(complexfloating[_64Bit], complex): # type: ignore[misc]
@overload
def __new__(
cls,
real: complex | SupportsComplex | SupportsFloat | SupportsIndex = ...,
imag: complex | SupportsFloat | SupportsIndex = ...,
/,
) -> Self: ...
@overload
def __new__(cls, real: _ConvertibleToComplex | None = ..., /) -> Self: ...

#
@property
def itemsize(self) -> L[16]: ...
@property
Expand Down Expand Up @@ -4917,9 +4939,15 @@ class character(flexible[_CharacterItemT_co], Generic[_CharacterItemT_co]):

class bytes_(character[bytes], bytes):
@overload
def __init__(self, value: object = ..., /) -> None: ...
def __new__(cls, o: object = ..., /) -> Self: ...
@overload
def __new__(cls, s: str, /, encoding: str, errors: str = ...) -> Self: ...

#
@overload
def __init__(self, o: object = ..., /) -> None: ...
@overload
def __init__(self, value: str, /, encoding: str = ..., errors: str = ...) -> None: ...
def __init__(self, s: str, /, encoding: str, errors: str = ...) -> None: ...

#
def __bytes__(self, /) -> bytes: ...
Expand Down
5 changes: 2 additions & 3 deletions test/static/reject/scalars.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ class A:
np.float32(3j) # type: ignore[arg-type] # pyright: ignore[reportArgumentType]
np.float32([1.0, 0.0, 0.0]) # type: ignore[arg-type] # pyright: ignore[reportArgumentType]

np.complex64([]) # type: ignore[arg-type] # pyright: ignore[reportArgumentType]
np.complex64(1, 2) # type: ignore[call-arg] # pyright: ignore[reportCallIssue]
np.complex64([]) # type: ignore[call-overload] # pyright: ignore[reportCallIssue,reportArgumentType]

np.datetime64(0) # type: ignore[call-overload] # pyright: ignore[reportCallIssue,reportArgumentType]

Expand All @@ -42,7 +41,7 @@ np.flexible(b"test") # type: ignore[abstract]
np.float64(value=0.0) # type: ignore[call-arg] # pyright: ignore[reportCallIssue]
np.int64(value=0) # type: ignore[call-arg] # pyright: ignore[reportCallIssue]
np.uint64(value=0) # type: ignore[call-arg] # pyright: ignore[reportCallIssue]
np.complex128(value=0.0j) # type: ignore[call-arg] # pyright: ignore[reportCallIssue]
np.complex128(value=0.0j) # type: ignore[call-overload] # pyright: ignore[reportCallIssue]
np.str_(value="bob") # type: ignore[call-overload] # pyright: ignore[reportCallIssue]
np.bytes_(value=b"test") # type: ignore[call-overload] # pyright: ignore[reportCallIssue]
np.void(value=b"test") # type: ignore[call-overload] # pyright: ignore[reportCallIssue]
Expand Down