Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite242181

Browse files
authored
TYP: restoregeneric.__hash__ (#30456)
1 parent7975630 commite242181

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

‎numpy/__init__.pyi‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3662,6 +3662,12 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]):
36623662
@abstractmethod
36633663
def__new__(cls,/,*args:Any,**kwargs:Any)->Self: ...
36643664

3665+
# NOTE: Technically this doesn't exist at runtime, but it is unlikely to lead to
3666+
# type-unsafe situations (the abstract scalar types cannot be instantiated
3667+
# themselves) and is convenient to have, so we include it regardless. See
3668+
# https://github.com/numpy/numpy/issues/30445 for use-cases and discussion.
3669+
def__hash__(self,/)->int: ...
3670+
36653671
def__buffer__(self,flags:int,/)->memoryview: ...
36663672

36673673
@overload
@@ -5807,6 +5813,10 @@ class bytes_(character[bytes], bytes): # type: ignore[misc]
58075813
@overload
58085814
def__new__(cls,value:str,/,encoding:str,errors:str="strict")->Self: ...
58095815

5816+
#
5817+
@override
5818+
def__hash__(self,/)->int: ...
5819+
58105820
#
58115821
def__bytes__(self,/)->bytes: ...
58125822

@@ -5816,6 +5826,10 @@ class str_(character[str], str): # type: ignore[misc]
58165826
@overload
58175827
def__new__(cls,value:bytes,/,encoding:str,errors:str="strict")->Self: ...
58185828

5829+
#
5830+
@override
5831+
def__hash__(self,/)->int: ...
5832+
58195833
# See `numpy._typing._ufunc` for more concrete nin-/nout-specific stubs
58205834
@final
58215835
classufunc:

‎numpy/typing/tests/data/pass/ndarray_misc.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from __future__importannotations
1010

1111
importoperator
12+
fromcollections.abcimportHashable
1213
fromtypingimportAny,cast
1314

1415
importnumpyasnp
@@ -192,3 +193,7 @@ class IntSubClass(np.ndarray[tuple[Any, ...], np.dtype[np.intp]]): ...
192193
A_void:npt.NDArray[np.void]=np.empty(3, [("yop",float), ("yap",float)])
193194
A_void["yop"]=A_float[:,0]
194195
A_void["yap"]=A_float[:,1]
196+
197+
# regression test for https://github.com/numpy/numpy/issues/30445
198+
deff(x:np.generic)->Hashable:
199+
returnx

‎tools/stubtest/allowlist.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ numpy\.(\w+\.)*integer\.bit_count
3939
numpy\.(\w+\.)*floating\.as_integer_ratio
4040
numpy\.(\w+\.)*floating\.is_integer
4141
numpy\.(\w+\.)*complexfloating\.__complex__
42+
# https://github.com/numpy/numpy/issues/30445#issuecomment-3665484402
43+
numpy\.(\w+\.)*generic\.__hash__
4244

4345
# intentionally missing deprecated module stubs
4446
numpy\.core\._dtype

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp