Run mypy on some test files, add iinfo/finfo annotations (#38220)

Summary:
Most test files have a ton of errors; there's not much point adding ignores for them though. The way of working is simply to run `mypy test/test_somefile.py`, fix up the errors, then add that file to the `files =` list in `mypy.ini`.

Can't add all of `test/*` by default, because the JIT test files have (on purpose) syntax errors that are meant to exercise the robustness of the JIT to bad annotations. Leave those alone for now.

_Depends on the ghstacked PRs in gh-38173, only the last 2 commits are new._
Pull Request resolved: https://github.com/pytorch/pytorch/pull/38220

Differential Revision: D21503481

Pulled By: ezyang

fbshipit-source-id: 63026e73201c549d64647a03a20a4c6687720244
This commit is contained in:
Ralf Gommers 2020-05-11 20:09:52 -07:00 committed by Facebook GitHub Bot
parent 6e66e8562f
commit cebf5a8767
3 changed files with 27 additions and 2 deletions

View File

@ -17,7 +17,10 @@ check_untyped_defs = True
files =
torch,
caffe2,
aten/src/ATen/function_wrapper.py
aten/src/ATen/function_wrapper.py,
test/test_complex.py,
test/test_type_hints.py,
test/test_type_info.py
# Minimum version supported - variable annotations were introduced

View File

@ -645,7 +645,8 @@ def gen_pyi(declarations_path, out):
for n in
['float32', 'float', 'float64', 'double', 'float16', 'bfloat16', 'half',
'uint8', 'int8', 'int16', 'short', 'int32', 'int', 'int64', 'long',
'complex32', 'complex64', 'complex128', 'quint8', 'qint8', 'qint32', 'bool']]
'complex32', 'complex64', 'cfloat', 'complex128', 'cdouble',
'quint8', 'qint8', 'qint32', 'bool']]
# Write out the stub
# ~~~~~~~~~~~~~~~~~~

View File

@ -38,6 +38,27 @@ class dtype:
# TODO: is_floating_point, is_complex, is_Signed, __reduce__
...
# Defined in torch/csrc/TypeInfo.cpp
class iinfo:
bits: _int
min: _int
max: _int
def __init__(self, dtype: _dtype) -> None: ...
class finfo:
bits: _float
min: _float
max: _float
eps: _float
tiny: _float
@overload
def __init__(self, dtype: _dtype) -> None: ...
@overload
def __init__(self) -> None: ...
${dtype_class_hints}
# Defined in torch/csrc/Layout.cpp