mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-06 12:20:52 +01:00
Add --check-untyped-defs to mypy.ini and test suite (#37594)
Summary: Also move the ignores for imports to the bottom in `mypy.ini`, those are much less interesting - start with the stuff people want to work on. Second commit tests the instructions: remove an ignore, fix the issue. Pull Request resolved: https://github.com/pytorch/pytorch/pull/37594 Differential Revision: D21434858 Pulled By: ezyang fbshipit-source-id: 4f1a6868cdb4cb59d072bcf105f48c3a5ba3ff98
This commit is contained in:
parent
30fc58cfcc
commit
46ed3349f3
|
|
@ -1,13 +0,0 @@
|
|||
### Optional type checking with mypy
|
||||
|
||||
mypy is an optional static typechecker that works with Python 3.
|
||||
To use it, install the following dependencies:
|
||||
```bash
|
||||
# Install dependencies
|
||||
pip install mypy mypy-extensions
|
||||
|
||||
# Run type checker in the pytorch/ directory
|
||||
mypy
|
||||
```
|
||||
|
||||
Note that the minimum version of MyPy that is supported is 0.770
|
||||
548
mypy.ini
548
mypy.ini
|
|
@ -4,8 +4,16 @@
|
|||
warn_unused_configs = True
|
||||
warn_redundant_casts = True
|
||||
show_error_codes = True
|
||||
check_untyped_defs = True
|
||||
|
||||
#
|
||||
# Note: test/ still has syntax errors so can't be added
|
||||
#
|
||||
# Typing tests is low priority, but enabling type checking on the
|
||||
# untyped test functions (using `--check-untyped-defs`) is still
|
||||
# high-value because it helps test the typing.
|
||||
#
|
||||
|
||||
# Note: test/ still have syntax errors so can't be added
|
||||
files =
|
||||
torch,
|
||||
caffe2,
|
||||
|
|
@ -16,6 +24,370 @@ files =
|
|||
# in Python 3.6
|
||||
python_version = 3.6
|
||||
|
||||
|
||||
#
|
||||
# Extension modules without stubs.
|
||||
#
|
||||
|
||||
[mypy-torch._C]
|
||||
ignore_missing_imports = True
|
||||
|
||||
[mypy-torch._C._jit_tree_views]
|
||||
ignore_missing_imports = True
|
||||
|
||||
[mypy-torch.for_onnx.onnx]
|
||||
ignore_missing_imports = True
|
||||
|
||||
#
|
||||
# Files with various errors. Mostly real errors, possibly some false
|
||||
# positives as well.
|
||||
#
|
||||
|
||||
[mypy-torch.distributed.*]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.functional.*]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.testing._internal.*]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.quantization.default_mappings]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.quantization.fuse_modules]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.quantization.observer]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.quantization.stubs]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.quantization.fake_quantize]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.quantization._quantize_script]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.quantization._numeric_suite]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.quasirandom]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.distributions.*]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.hub]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch._classes]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch._six]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.random]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.jit]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.jit.frontend]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.jit.quantized]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.jit.quantized.modules.utils]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.jit.supported_ops]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.jit.supported_tensor_ops]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.jit.unsupported_tensor_ops]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch._jit_internal]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.jit._builtins]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.jit._logging]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.jit._recursive]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.jit.annotations]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.sparse]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.tensor]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch._tensor_str]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.nn.parallel._functions]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.nn.quantized.functional]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.nn.quantized.modules]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.nn.quantized.modules.activation]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.nn.quantized.modules.normalization]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.nn.quantized.modules.utils]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.nn.qat.modules.activations]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.nn.qat.modules.conv]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.nn.quantized.dynamic.modules.rnn]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.nn.quantized.dynamic.modules.linear]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.nn.quantized.modules.conv]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.nn.quantized.modules.functional_modules]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.cuda.*]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch._lobpcg]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch._appdirs]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.storage]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch._utils]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch._overrides]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.utils.bundled_inputs]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.utils.tensorboard.*]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.contrib._tensorboard_vis]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.utils.cpp_extension]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.utils.bottleneck.__main__]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.utils.data]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.utils.data._utils.signal_handling]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.utils.data._utils.collate]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.utils.data._utils.worker]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.utils.data.dataset]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.utils.data.distributed]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.utils.checkpoint]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.utils.collect_env]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.nn.utils.prune]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.nn.utils.memory_format]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.nn.cpp]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.nn.functional]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.serialization]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.utils]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.utils.show_pickle]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.utils.hipify.hipify_python]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.autograd._functions.tensor]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.autograd.function]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.autograd.functional]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.autograd.profiler]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.autograd.gradcheck]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.autograd.anomaly_mode]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.autograd.variable]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.nn.quantized.modules.batchnorm]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.nn.quantized.modules.linear]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.nn.intrinsic.quantized.modules.conv_relu]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.nn.intrinsic.quantized.modules.bn_relu]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.nn.intrinsic.quantized.modules.linear_relu]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.nn.intrinsic.qat.modules.conv_fused]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.onnx.symbolic_opset8]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.onnx.symbolic_opset9]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.onnx.symbolic_opset11]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.onnx.symbolic_caffe2]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.onnx.symbolic_helper]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.onnx.symbolic_registry]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.onnx.utils]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.multiprocessing]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.multiprocessing.reductions]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.multiprocessing.queue]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.multiprocessing.pool]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.multiprocessing.spawn]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.backends.cudnn.rnn]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.backends.cuda]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.backends.cudnn]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.backends.quantized]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-caffe2.python.*]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-caffe2.proto.*]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-caffe2.core.nomnigraph.op_gen]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-caffe2.contrib.playground.*]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-caffe2.contrib.gloo.gloo_test]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-caffe2.contrib.warpctc.ctc_ops_test]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-caffe2.contrib.prof.cuda_profile_ops_test]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-caffe2.contrib.nccl.nccl_ops_test]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-caffe2.distributed.store_ops_test_util]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-caffe2.experiments.python.device_reduce_sum_bench]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-caffe2.experiments.python.SparseTransformer]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-caffe2.experiments.python.convnet_benchmarks]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-caffe2.contrib.aten.docs.sample]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-caffe2.contrib.tensorboard.tensorboard_exporter]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-caffe2.contrib.tensorboard.tensorboard_exporter_test]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-caffe2.quantization.server.*]
|
||||
ignore_errors = True
|
||||
|
||||
#
|
||||
# Third party dependencies that don't have types.
|
||||
#
|
||||
|
|
@ -103,177 +475,3 @@ ignore_missing_imports = True
|
|||
|
||||
[mypy-skimage.*]
|
||||
ignore_missing_imports = True
|
||||
|
||||
#
|
||||
# Extension modules without stubs.
|
||||
#
|
||||
|
||||
[mypy-torch._C]
|
||||
ignore_missing_imports = True
|
||||
|
||||
[mypy-torch._C._jit_tree_views]
|
||||
ignore_missing_imports = True
|
||||
|
||||
[mypy-torch.for_onnx.onnx]
|
||||
ignore_missing_imports = True
|
||||
|
||||
#
|
||||
# Files with various errors. Mostly real errors, possibly some false
|
||||
# positives as well.
|
||||
#
|
||||
|
||||
[mypy-torch.distributed.*]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.functional.*]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.testing._internal.*]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.quantization.default_mappings]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.quantization.observer]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.quantization.fake_quantize]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.quantization._quantize_script]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.distributions.*]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.jit]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.jit.quantized]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch._jit_internal]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.jit._builtins]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.jit._logging]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.jit.annotations]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.sparse]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.tensor]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch._tensor_str]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.nn.quantized.functional]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.nn.quantized.modules.activation]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.nn.qat.modules.activations]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.nn.quantized.dynamic.modules.rnn]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.nn.quantized.modules.conv]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.cuda.*]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch._lobpcg]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch._appdirs]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.storage]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.utils.bundled_inputs]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.utils.data]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.utils.data.dataset]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.utils.data.distributed]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.nn.utils.prune]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.nn.cpp]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.nn.functional]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.utils.show_pickle]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.utils.hipify.hipify_python]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.autograd.function]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.autograd.variable]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.serialization]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.nn.quantized.modules.linear]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.nn.intrinsic.quantized.modules.conv_relu]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.nn.intrinsic.qat.modules.conv_fused]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.onnx.symbolic_opset8]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.onnx.symbolic_helper]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.multiprocessing]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.multiprocessing.spawn]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.backends.cuda]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.backends.cudnn]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-torch.backends.quantized]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-caffe2.python.*]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-caffe2.proto.*]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-caffe2.contrib.gloo.gloo_test]
|
||||
ignore_errors = True
|
||||
|
||||
[mypy-caffe2.quantization.server.pool_dnnlowp_op_test]
|
||||
ignore_errors = True
|
||||
|
|
|
|||
|
|
@ -211,7 +211,8 @@ class TestTypeHints(TestCase):
|
|||
cwd = os.getcwd()
|
||||
try:
|
||||
os.chdir(repo_rootdir)
|
||||
subprocess.run([sys.executable, '-mmypy'], check=True)
|
||||
subprocess.run([sys.executable, '-mmypy', '--check-untyped-defs',
|
||||
'--follow-imports', 'silent'], check=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
raise AssertionError("mypy failed. Look above this error for mypy's output.")
|
||||
finally:
|
||||
|
|
|
|||
|
|
@ -46,6 +46,8 @@ class layout: ...
|
|||
|
||||
strided : layout = ...
|
||||
|
||||
sparse_coo : layout = ...
|
||||
|
||||
class memory_format: ...
|
||||
|
||||
contiguous_format: memory_format = ...
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ import time
|
|||
from collections import defaultdict
|
||||
from functools import partial
|
||||
|
||||
import torch
|
||||
|
||||
|
||||
# Unfortunately it doesn't seem as if there was any way to get TensorBoard to do
|
||||
# anything without having TF installed, and so this file has a hard dependency on it
|
||||
|
|
|
|||
|
|
@ -6,7 +6,16 @@ import inspect
|
|||
import string
|
||||
from textwrap import dedent
|
||||
from torch._six import PY2
|
||||
from torch._C._jit_tree_views import *
|
||||
from torch._C._jit_tree_views import (
|
||||
ClassDef, Ident, Stmt, Decl, Def, Var,
|
||||
EmptyTypeAnnotation, Param, ExprStmt, Assign,
|
||||
Delete, Return, Raise, Assert, AugAssign, While,
|
||||
For, If, Pass, Break, Continue, Apply, Dots, Select,
|
||||
TrueLiteral, FalseLiteral, NoneLiteral, Starred,
|
||||
ListLiteral, TupleLiteral, DictLiteral, Const,
|
||||
StringLiteral, ListComp, Attribute, BinOp, UnaryOp,
|
||||
SliceExpr, Subscript, TernaryIf
|
||||
)
|
||||
from torch._utils_internal import get_source_lines_and_file
|
||||
|
||||
from torch._jit_internal import SourceContext
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class ChannelShuffle(Module):
|
|||
__constants__ = ['groups']
|
||||
|
||||
def __init__(self, groups):
|
||||
super(ChanelShuffle, self).__init__()
|
||||
super(ChannelShuffle, self).__init__()
|
||||
self.groups = groups
|
||||
|
||||
def forward(self, input):
|
||||
|
|
|
|||
|
|
@ -50,5 +50,7 @@ class FileBaton:
|
|||
|
||||
def release(self):
|
||||
'''Releases the baton and removes its file.'''
|
||||
os.close(self.fd)
|
||||
if self.fd is not None:
|
||||
os.close(self.fd)
|
||||
|
||||
os.remove(self.lock_file_path)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user