diff --git a/numpy-stubs/__init__.pyi b/numpy-stubs/__init__.pyi index c51f3a6..453b65d 100644 --- a/numpy-stubs/__init__.pyi +++ b/numpy-stubs/__init__.pyi @@ -417,10 +417,18 @@ class datetime64: class integer(number, _real_generic): ... class signedinteger(integer): ... -class int8(signedinteger): ... -class int16(signedinteger): ... -class int32(signedinteger): ... -class int64(signedinteger): ... + +class int8(signedinteger): + def __init__(self, value: SupportsInt = ...) -> None: ... + +class int16(signedinteger): + def __init__(self, value: SupportsInt = ...) -> None: ... + +class int32(signedinteger): + def __init__(self, value: SupportsInt = ...) -> None: ... + +class int64(signedinteger): + def __init__(self, value: SupportsInt = ...) -> None: ... class timedelta64(signedinteger): def __init__(self, _data: Any = ..., _format: str = ...) -> None: ... @@ -441,10 +449,19 @@ class timedelta64(signedinteger): def __mod__(self, other: timedelta64) -> timedelta64: ... class unsignedinteger(integer): ... -class uint8(unsignedinteger): ... -class uint16(unsignedinteger): ... -class uint32(unsignedinteger): ... -class uint64(unsignedinteger): ... + +class uint8(unsignedinteger): + def __init__(self, value: SupportsInt = ...) -> None: ... + +class uint16(unsignedinteger): + def __init__(self, value: SupportsInt = ...) -> None: ... + +class uint32(unsignedinteger): + def __init__(self, value: SupportsInt = ...) -> None: ... + +class uint64(unsignedinteger): + def __init__(self, value: SupportsInt = ...) -> None: ... + class inexact(number): ... class floating(inexact, _real_generic): ... class float16(floating): ... diff --git a/tests/fail/scalars.py b/tests/fail/scalars.py index 38749ed..517e8f2 100644 --- a/tests/fail/scalars.py +++ b/tests/fail/scalars.py @@ -37,3 +37,18 @@ td_64 / dt_64 # E: No overload td_64 % 1 # E: Unsupported operand types td_64 % dt_64 # E: Unsupported operand types + + +class A: + def __float__(self): + return 1.0 + + +np.int8(A()) # E: incompatible type +np.int16(A()) # E: incompatible type +np.int32(A()) # E: incompatible type +np.int64(A()) # E: incompatible type +np.uint8(A()) # E: incompatible type +np.uint16(A()) # E: incompatible type +np.uint32(A()) # E: incompatible type +np.uint64(A()) # E: incompatible type diff --git a/tests/pass/scalars.py b/tests/pass/scalars.py index 302b53d..c219bef 100644 --- a/tests/pass/scalars.py +++ b/tests/pass/scalars.py @@ -7,9 +7,14 @@ def __complex__(self): return 3j +class B: + def __int__(self): + return 4 + + class A: def __float__(self): - return 4 + return 4.0 np.complex32(3) @@ -20,7 +25,7 @@ def __float__(self): np.int16(3.4) np.int32(4) np.int64(-1) -np.uint8(A()) +np.uint8(B()) np.uint32() np.float16(A())