Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Add annotations for the remaining np.generic aliases #18284

Merged
merged 1 commit into from
Feb 1, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 11 additions & 7 deletions numpy/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -335,23 +335,20 @@ bincount: Any
bitwise_not: Any
blackman: Any
bmat: Any
bool8: Any
broadcast: Any
broadcast_arrays: Any
broadcast_to: Any
busday_count: Any
busday_offset: Any
busdaycalendar: Any
byte_bounds: Any
bytes0: Any
c_: Any
can_cast: Any
cast: Any
chararray: Any
column_stack: Any
common_type: Any
compare_chararrays: Any
complex256: Any
concatenate: Any
conj: Any
copy: Any
Expand Down Expand Up @@ -387,7 +384,6 @@ fix: Any
flip: Any
fliplr: Any
flipud: Any
float128: Any
format_parser: Any
frombuffer: Any
fromfile: Any
Expand Down Expand Up @@ -471,7 +467,6 @@ nditer: Any
nested_iters: Any
newaxis: Any
numarray: Any
object0: Any
ogrid: Any
packbits: Any
pad: Any
Expand Down Expand Up @@ -522,7 +517,6 @@ sinc: Any
sort_complex: Any
source: Any
split: Any
string_: Any
take_along_axis: Any
tile: Any
trapz: Any
Expand All @@ -545,7 +539,6 @@ unwrap: Any
vander: Any
vdot: Any
vectorize: Any
void0: Any
vsplit: Any
where: Any
who: Any
Expand Down Expand Up @@ -1667,13 +1660,17 @@ class bool_(generic):
__gt__: _ComparisonOp[_NumberLike_co, _ArrayLikeNumber_co]
__ge__: _ComparisonOp[_NumberLike_co, _ArrayLikeNumber_co]

bool8 = bool_

class object_(generic):
def __init__(self, __value: object = ...) -> None: ...
@property
def real(self: _ArraySelf) -> _ArraySelf: ...
@property
def imag(self: _ArraySelf) -> _ArraySelf: ...

object0 = object_

class datetime64(generic):
@overload
def __init__(
Expand Down Expand Up @@ -1869,6 +1866,7 @@ class floating(inexact[_NBit1]):
float16 = floating[_16Bit]
float32 = floating[_32Bit]
float64 = floating[_64Bit]
float128 = floating[_128Bit]

half = floating[_NBitHalf]
single = floating[_NBitSingle]
Expand Down Expand Up @@ -1903,6 +1901,7 @@ class complexfloating(inexact[_NBit1], Generic[_NBit1, _NBit2]):

complex64 = complexfloating[_32Bit, _32Bit]
complex128 = complexfloating[_64Bit, _64Bit]
complex256 = complexfloating[_128Bit, _128Bit]

csingle = complexfloating[_NBitSingle, _NBitSingle]
singlecomplex = complexfloating[_NBitSingle, _NBitSingle]
Expand All @@ -1925,6 +1924,8 @@ class void(flexible):
self, val: ArrayLike, dtype: DTypeLike, offset: int = ...
) -> None: ...

void0 = void

class character(flexible): # type: ignore
def __int__(self) -> int: ...
def __float__(self) -> float: ...
Expand All @@ -1940,6 +1941,9 @@ class bytes_(character, bytes):
self, __value: str, encoding: str = ..., errors: str = ...
) -> None: ...

string_ = bytes_
bytes0 = bytes_

class str_(character, str):
@overload
def __init__(self, __value: object = ...) -> None: ...
Expand Down
5 changes: 5 additions & 0 deletions numpy/typing/tests/data/pass/scalars.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ def __float__(self) -> float:

# Aliases
np.str0()
np.bool8()
np.bytes0()
np.string_()
np.object0()
np.void0(0)

np.byte()
np.short()
Expand Down
5 changes: 5 additions & 0 deletions numpy/typing/tests/data/reveal/scalars.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
# Aliases
reveal_type(np.unicode_()) # E: numpy.str_
reveal_type(np.str0()) # E: numpy.str_
reveal_type(np.bool8()) # E: numpy.bool_
reveal_type(np.bytes0()) # E: numpy.bytes_
reveal_type(np.string_()) # E: numpy.bytes_
reveal_type(np.object0()) # E: numpy.object_
reveal_type(np.void0(0)) # E: numpy.void

reveal_type(np.byte()) # E: {byte}
reveal_type(np.short()) # E: {short}
Expand Down