diff options
author | Josh Wilson <person142@users.noreply.github.com> | 2020-06-06 15:31:33 -0700 |
---|---|---|
committer | Josh Wilson <person142@users.noreply.github.com> | 2020-06-06 15:31:33 -0700 |
commit | 11b95d15f10c2bc652ed19d5e27efa0384396cb8 (patch) | |
tree | 8d6f2020f6982fc9f2389796daca1429387f576e /numpy/tests/reveal/scalars.py | |
parent | a5d021a1b6f439a19812926bc4d796ef5f346c44 (diff) | |
download | numpy-11b95d15f10c2bc652ed19d5e27efa0384396cb8.tar.gz |
ENH: add type stubs from numpy-stubs
Add the type stubs and tests from numpy-stubs. Things this entails:
- Copy over the stubs (numpy/__init__.pyi and
numpy/core/_internal.pyi)
- The only modification made was removing `ndarray.tostring` since
it is deprecated
- Update some setup.py files to include pyi files
- Move the tests from numpy-stubs/tests into numpy/tests
- Skip them if mypy is not installed (planning on setting up CI in a
future PR)
- Add a mypy.ini; use it to configure mypy in the tests
- It tells mypy where to find NumPy in the test env
- It ignores internal NumPy type errors (since we only want to
consider errors from the tests cases)
- Some small edits were made to fix test cases that were emitting
deprecation warnings
- Add numpy/py.typed so that the types are picked up in an
installed version of NumPy
Diffstat (limited to 'numpy/tests/reveal/scalars.py')
-rw-r--r-- | numpy/tests/reveal/scalars.py | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/numpy/tests/reveal/scalars.py b/numpy/tests/reveal/scalars.py new file mode 100644 index 000000000..8a9555fc3 --- /dev/null +++ b/numpy/tests/reveal/scalars.py @@ -0,0 +1,30 @@ +import numpy as np + +x = np.complex64(3 + 2j) + +reveal_type(x.real) # E: numpy.float32 +reveal_type(x.imag) # E: numpy.float32 + +reveal_type(x.real.real) # E: numpy.float32 +reveal_type(x.real.imag) # E: numpy.float32 + +reveal_type(x.itemsize) # E: int +reveal_type(x.shape) # E: tuple[builtins.int] +reveal_type(x.strides) # E: tuple[builtins.int] + +# Time structures +dt = np.datetime64(0, "D") +td = np.timedelta64(0, "D") + +reveal_type(dt + td) # E: numpy.datetime64 +reveal_type(dt + 1) # E: numpy.datetime64 +reveal_type(dt - dt) # E: numpy.timedelta64 +reveal_type(dt - 1) # E: numpy.timedelta64 + +reveal_type(td + td) # E: numpy.timedelta64 +reveal_type(td + 1) # E: numpy.timedelta64 +reveal_type(td - td) # E: numpy.timedelta64 +reveal_type(td - 1) # E: numpy.timedelta64 +reveal_type(td / 1.0) # E: numpy.timedelta64 +reveal_type(td / td) # E: float +reveal_type(td % td) # E: numpy.timedelta64 |