Revert D25757721: [pytorch][PR] Run mypy on more test files

Test Plan: revert-hammer

Differential Revision:
D25757721 (b7bfc723d3)

Original commit changeset: 44c396d8da9e

fbshipit-source-id: 58437d719285a4fecd8c05e487cc86fc2cebadff
This commit is contained in:
Mike Ruberry 2021-01-05 15:16:12 -08:00 committed by Facebook GitHub Bot
parent d1a56fcd9d
commit 9529ae3776
6 changed files with 14 additions and 30 deletions

View File

@ -17,13 +17,8 @@ check_untyped_defs = True
files =
torch,
caffe2,
test/test_bundled_images.py,
test/test_bundled_inputs.py,
test/test_complex.py,
test/test_dataset.py,
test/test_expecttest.py,
test/test_futures.py,
test/test_numpy_interop.py,
test/test_torch.py,
test/test_type_hints.py,
test/test_type_info.py
@ -124,12 +119,6 @@ ignore_errors = True
[mypy-torch.overrides]
ignore_errors = True
#
# Adding type annotations to caffe2 is probably not worth the effort
# only work on this if you have a specific reason for it, otherwise
# leave these ignores as they are.
#
[mypy-caffe2.python.*]
ignore_errors = True

View File

@ -1,7 +1,5 @@
#!/usr/bin/env python3
import io
from typing import List
import torch
import torch.utils.bundled_inputs
from torch.testing._internal.common_utils import TestCase, run_tests
@ -29,7 +27,7 @@ class TestBundledInputs(TestCase):
sm = torch.jit.script(SingleTensorModel())
original_size = model_size(sm)
get_expr : List[str] = []
get_expr = []
samples = [
# Tensor with small numel and small storage.
(torch.tensor([1]),),

View File

@ -4,7 +4,6 @@ import unittest
import string
import textwrap
import doctest
from typing import Dict, Any
import hypothesis
from hypothesis.strategies import text, integers, composite, sampled_from, booleans
@ -39,7 +38,7 @@ class TestExpectTest(expecttest.TestCase):
r3 = {r}{quote}placeholder3{quote}
""".format(r='r' if raw else '', quote=quote * 3)
new_prog = expecttest.replace_string_literal(textwrap.dedent(prog), 2, t)[0]
ns : Dict[str, Any] = {}
ns = {}
exec(new_prog, ns)
msg = "program was:\n{}".format(new_prog)
self.assertEqual(ns['r'], 'placeholder', msg=msg) # noqa: F821

View File

@ -47,8 +47,10 @@ class TestNumPyInterop(TestCase):
else:
# can't directly use min and max, because for int64_t, max - min
# is greater than int64_t range and triggers UB.
low = max(torch.iinfo(dtype).min, int(-1e10))
high = min(torch.iinfo(dtype).max, int(1e10))
dtype_info = torch.iinfo(dtype)
low = max(dtype_info.min, int(-1e10))
high = min(dtype_info.max, int(1e10))
dtype_info = torch.iinfo(dtype)
t = torch.empty(shape, dtype=torch.int64).random_(low, high)
return t.to(dtype)
@ -270,12 +272,10 @@ class TestNumPyInterop(TestCase):
]
for tp, dtype in zip(types, dtypes):
if np.dtype(dtype).kind == 'u':
# .type expects a XxxTensor, which have no type hints on
# purpose, so ignore during mypy type checking
x = torch.Tensor([1, 2, 3, 4]).type(tp) # type: ignore
x = torch.Tensor([1, 2, 3, 4]).type(tp)
array = np.array([1, 2, 3, 4], dtype=dtype)
else:
x = torch.Tensor([1, -2, 3, -4]).type(tp) # type: ignore
x = torch.Tensor([1, -2, 3, -4]).type(tp)
array = np.array([1, -2, 3, -4], dtype=dtype)
# Test __array__ w/o dtype argument
@ -309,7 +309,7 @@ class TestNumPyInterop(TestCase):
float_types = [torch.DoubleTensor, torch.FloatTensor]
float_dtypes = [np.float64, np.float32]
for tp, dtype in zip(float_types, float_dtypes):
x = torch.Tensor([1, 2, 3, 4]).type(tp) # type: ignore
x = torch.Tensor([1, 2, 3, 4]).type(tp)
array = np.array([1, 2, 3, 4], dtype=dtype)
for func in ['sin', 'sqrt', 'ceil']:
ufunc = getattr(np, func)
@ -321,7 +321,7 @@ class TestNumPyInterop(TestCase):
# Test functions with boolean return value
for tp, dtype in zip(types, dtypes):
x = torch.Tensor([1, 2, 3, 4]).type(tp) # type: ignore
x = torch.Tensor([1, 2, 3, 4]).type(tp)
array = np.array([1, 2, 3, 4], dtype=dtype)
geq2_x = np.greater_equal(x, 2)
geq2_array = np.greater_equal(array, 2).astype('uint8')
@ -360,7 +360,7 @@ class TestNumPyInterop(TestCase):
self.assertEqual(torch.ones([2, 2, 2, 2]).mean(scalar), torch.ones([2, 2, 2, 2]).mean(np_val))
# numpy integral type parses like a python int in custom python bindings:
self.assertEqual(torch.Storage(np_val).size(), scalar) # type: ignore
self.assertEqual(torch.Storage(np_val).size(), scalar)
tensor = torch.tensor([2], dtype=torch.int)
tensor[0] = np_val

View File

@ -3,7 +3,6 @@ import unittest
import traceback
import os
import string
from typing import Tuple
# This file implements expect tests (also known as "golden" tests).
@ -140,8 +139,7 @@ RE_EXPECT = re.compile(r"^(?P<suffix>[^\n]*?)"
r"(?P<raw>r?)", re.DOTALL)
def replace_string_literal(src : str, lineno : int,
new_string : str) -> Tuple[str, int]:
def replace_string_literal(src, lineno, new_string):
r"""
Replace a triple quoted string literal with new contents.
Only handles printable ASCII correctly at the moment. This

View File

@ -1,5 +1,5 @@
#!/usr/bin/env python3
from typing import Any, TypeVar, Optional, Tuple, List, NamedTuple, Union, Sequence
from typing import Any, TypeVar, Optional, Tuple, List, NamedTuple, Union
import textwrap
import torch
from torch._C import TupleType, OptionalType, ListType
@ -17,7 +17,7 @@ class InflatableArg(NamedTuple):
def augment_model_with_bundled_inputs(
model: torch.jit.ScriptModule,
inputs: Optional[Sequence[Tuple[Any, ...]]] = None,
inputs: Optional[List[Tuple[Any, ...]]] = None,
_receive_inflate_expr: Optional[List[str]] = None, # For debugging.
) -> None:
"""Add bundled sample inputs to a model.