Skip to content

Commit

Permalink
Run mypy on some test files, add iinfo/finfo annotations (pytorch#38220)
Browse files Browse the repository at this point in the history
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 pytorchgh-38173, only the last 2 commits are new._
Pull Request resolved: pytorch#38220

Differential Revision: D21503481

Pulled By: ezyang

fbshipit-source-id: 63026e73201c549d64647a03a20a4c6687720244
  • Loading branch information
rgommers authored and facebook-github-bot committed May 12, 2020
1 parent 6e66e85 commit cebf5a8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
5 changes: 4 additions & 1 deletion mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tools/pyi/gen_pyi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# ~~~~~~~~~~~~~~~~~~
Expand Down
21 changes: 21 additions & 0 deletions torch/_C/__init__.pyi.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cebf5a8

Please sign in to comment.