Skip to content

Commit

Permalink
Merge pull request #18284 from BvB93/aliases
Browse files Browse the repository at this point in the history
ENH: Add annotations for the remaining `np.generic` aliases
  • Loading branch information
charris committed Feb 1, 2021
2 parents c03d892 + 709b671 commit ac76769
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
18 changes: 11 additions & 7 deletions numpy/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -338,23 +338,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 @@ -390,7 +387,6 @@ fix: Any
flip: Any
fliplr: Any
flipud: Any
float128: Any
format_parser: Any
frombuffer: Any
fromfile: Any
Expand Down Expand Up @@ -474,7 +470,6 @@ nditer: Any
nested_iters: Any
newaxis: Any
numarray: Any
object0: Any
ogrid: Any
packbits: Any
pad: Any
Expand Down Expand Up @@ -525,7 +520,6 @@ sinc: Any
sort_complex: Any
source: Any
split: Any
string_: Any
take_along_axis: Any
tile: Any
trapz: Any
Expand All @@ -548,7 +542,6 @@ unwrap: Any
vander: Any
vdot: Any
vectorize: Any
void0: Any
vsplit: Any
where: Any
who: Any
Expand Down Expand Up @@ -1996,13 +1989,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 @@ -2198,6 +2195,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 @@ -2232,6 +2230,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 @@ -2254,6 +2253,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 @@ -2269,6 +2270,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

0 comments on commit ac76769

Please sign in to comment.