Skip to content

Commit a793b84

Browse files
committed
chore(lint): disable mypy warn_any_return
ghstack-source-id: bd109a0 Pull Request resolved: #248
1 parent 5ead41d commit a793b84

File tree

12 files changed

+27
-21
lines changed

12 files changed

+27
-21
lines changed

onnxscript/backend/onnx_backend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def _read_proto_from_file(full):
7474
seq = onnx.SequenceProto()
7575
try:
7676
seq.ParseFromString(serialized)
77-
loaded = to_list(seq)
77+
loaded = to_list(seq) # type: ignore[assignment]
7878
except Exception: # pylint: disable=W0703
7979
try:
8080
loaded = onnx.load_model_from_string(serialized)

onnxscript/backend/onnx_export.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,10 @@ def _python_make_node_graph(self, graph, opsets, indent=0, output_names=None):
207207
if hasattr(graph, "initializer"):
208208
for init in graph.initializer:
209209
node = make_node(
210-
"Constant", [], [self._rename_variable(init.name)], value=init
210+
"Constant",
211+
[],
212+
[self._rename_variable(init.name)], # type: ignore[list-item]
213+
value=init,
211214
)
212215
code.append(self._python_make_node(node, opsets, indent=indent))
213216
if hasattr(graph, "sparse_initializer") and len(graph.sparse_initializer) > 0:

onnxscript/function_libs/tools/torch_aten/generate_aten_signatures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def format_arg_name(arg: torchgen.model.Argument) -> str:
192192
"""Returns the python compatible name of the given argument."""
193193
if arg.name == "from":
194194
return f"{arg.name}_"
195-
return arg.name # type: ignore[no-any-return]
195+
return arg.name
196196

197197

198198
def create_signature(func: torchgen.model.NativeFunction) -> cg.FunctionDef:

onnxscript/irbuilder.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import io
88
import logging
99
import warnings
10-
from typing import Any, Dict, Optional, Sequence, Tuple, Union
10+
from typing import Any, Optional, Sequence
1111

1212
import onnx
1313
from onnx import ValueInfoProto, helper
@@ -185,7 +185,7 @@ def __init__(self, name: str, domain: str = "") -> None:
185185
self.stmts: list[IRStmt] = []
186186
self.attrs: list[str] = [] # attribute parameters
187187
self.attr_protos: list[
188-
onnx.AttributeProto
188+
IRAttributeValue
189189
] = [] # attribute parameters with default value
190190
self.called_functions: dict[str, onnx.FunctionProto] = {}
191191
self.docstring: str = ""
@@ -218,7 +218,7 @@ def append_input(self, name: IRVar) -> None:
218218
def append_output(self, name: IRVar) -> None:
219219
self.outputs.append(name)
220220

221-
def add_attr_parameter(self, attr: Union[str, IRAttributeValue]) -> None:
221+
def add_attr_parameter(self, attr: str | IRAttributeValue) -> None:
222222
if isinstance(attr, IRAttributeValue):
223223
self.attr_protos.append(attr)
224224
else:
@@ -324,7 +324,7 @@ def to_proto(f):
324324

325325
def to_graph_and_functions(
326326
self, use_default_type: bool = True
327-
) -> Tuple[onnx.GraphProto, dict[str, onnx.FunctionProto]]:
327+
) -> tuple[onnx.GraphProto, dict[str, onnx.FunctionProto]]:
328328
"""Converts this instance into a `onnx.GraphProto` and a map from
329329
function-name to `onnx.FunctionProto`.
330330
@@ -360,7 +360,7 @@ def to_graph_proto(self, use_default_type: bool = True) -> onnx.GraphProto:
360360
graph, _ = self.to_graph_and_functions(use_default_type=use_default_type)
361361
return graph
362362

363-
def get_opset_import(self) -> Dict[str, int]:
363+
def get_opset_import(self) -> dict[str, int]:
364364
func_opset_imports = {}
365365
for s in self.stmts:
366366
if s.callee.opset.domain not in func_opset_imports:

onnxscript/main.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import inspect
1010
import sys
1111
import textwrap
12+
from typing import Any, Callable, Optional
1213

1314
import onnx.helper
1415

@@ -52,7 +53,11 @@ def script_check(f: ast.FunctionDef, opset, global_names, source, default_opset=
5253
return convert.top_level_stmt(f)
5354

5455

55-
def script(opset=None, default_opset=None, **kwargs):
56+
def script(
57+
opset: Optional[values.Opset] = None,
58+
default_opset: Optional[values.Opset] = None,
59+
**kwargs: Any,
60+
) -> Callable[[Callable[..., Any]], onnxscript.OnnxFunction]:
5661
"""Main decorator. Declares a function as an onnx function.
5762
5863
Args:

onnxscript/tensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def __float__(self) -> float:
5555
return float(self.value)
5656

5757
def __index__(self) -> int:
58-
return self.value.__index__() # type: ignore[no-any-return]
58+
return self.value.__index__()
5959

6060
def __getitem__(self, index):
6161
op = self._opset

onnxscript/test/common/onnx_script_test_case.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ def setUpClass(cls):
5454
try:
5555
# experimental version
5656
# pylint: disable=no-value-for-parameter
57-
cls.all_test_cases = node_test.collect_testcases() # type: ignore[attr-defined]
57+
cls.all_test_cases = node_test.collect_testcases() # type: ignore[attr-defined,call-arg]
5858
# pylint: enable=no-value-for-parameter
5959
except TypeError:
6060
# official version
61-
cls.all_test_cases = node_test.collect_testcases(None) # type: ignore[attr-defined]
61+
cls.all_test_cases = node_test.collect_testcases(None) # type: ignore[attr-defined,arg-type]
6262

6363
def _create_model_from_param(
6464
self, param: FunctionTestParams, onnx_case_model: onnx.ModelProto

onnxscript/test/function_libs/torch_aten/ops_correctness_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ def wrapped(fn):
156156
# Modify this section ##########################################################
157157

158158
# Ops to be tested for numerical consistency between onnx and pytorch
159-
OPINFO_FUNCTION_MAPPING = {
159+
# Find the names of the OpInfos in torch/testing/_internal/common_methods_invocations.py
160+
OPINFO_FUNCTION_MAPPING: dict[str, Callable[..., Any]] = {
160161
"add": core_ops.aten_add,
161162
"mul": core_ops.aten_mul,
162163
"nn.functional.elu": nn_ops.aten_elu,

onnxscript/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from onnx.printer import to_text as proto2text
2121
except ImportError:
2222

23-
def proto2text(x): # pylint: disable=unused-argument
23+
def proto2text(_: Any) -> str:
2424
return "<print utility unavailable>"
2525

2626

onnxscript/values.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def __contains__(self, opname):
6363
return False
6464

6565
def __str__(self) -> str:
66-
return self.domain # type: ignore[no-any-return]
66+
return self.domain
6767

6868
def __getattr__(self, attr: str):
6969
try:

0 commit comments

Comments
 (0)