-
-
Notifications
You must be signed in to change notification settings - Fork 31
Unsigned int constructors too generous #72
Comments
Would you kindly let me know what exactly needs to be done so that I can try working on the issue? |
Hey @rajatdiptabiswas, so what will need to be done is adding more specific constructors for things in the signed integer hierarchy: https://github.com/numpy/numpy-stubs/blob/master/numpy-stubs/__init__.pyi#L420 and the unsigned integer hierarchy: https://github.com/numpy/numpy-stubs/blob/master/numpy-stubs/__init__.pyi#L444 The constructors will be similar to the generic one here: https://github.com/numpy/numpy-stubs/blob/master/numpy-stubs/__init__.pyi#L402 but will not longer include |
Thanks for the clarification @person142 |
Hi @person142 I have tried looking into the issue and these are the things I believe I should be doing. For each of the classes Hence each of the class int64(signedinteger):
def __init__(self, value: SupportsInt = ...) -> None: ...
class uint64(unsignedinteger):
def __init__(self, value: SupportsInt = ...) -> None: ... instead of the current implementation class int64(signedinteger): ...
class uint64(unsignedinteger): ... Would you kindly confirm if these are correct? I also needed some help writing the tests. I believe I should edit the file I am new to writing tests and anything that might help me learn and complete this task would be amazing. I shall start working on these as soon as you confirm. Thanks in advance! |
Yes, that looks correct.
Since we are allowing less in the constructor, I would add cases to class A:
def __float__(self):
return 1.0
np.uint8(A()) # E: <whatever-error-mypy-gives>
... Note that you can run the tests by doing |
Fixes numpy#72 - Removed SupportsFloat from the classes int8, int16, int32, int64, uint8, uint16, uint32, and uint64 - Removed a test from tests/pass/scalars.py - Added several tests to tests/fail/scalars.py
I have made the changes you mentioned @person142. Kindly take a look as to whether I have made them correctly. If you find something wrong please let me know. I'll make the necessary updates! These are the changes that I have made:
|
This comment has been minimized.
This comment has been minimized.
Fixes #72 - Removed SupportsFloat from the classes int8, int16, int32, int64, uint8, uint16, uint32, and uint64 - Update tests/pass/scalars.py - Added several tests to tests/fail/scalars.py
xref #70
The code
fails at runtime, but passes type checking. The reason is here:
https://github.com/numpy/numpy-stubs/blob/master/numpy-stubs/__init__.pyi#L402
where the constructor of
number
is:The text was updated successfully, but these errors were encountered: