Skip to content

Commit e031a74

Browse files
committed
Enable mypy lintrunner, Part 5 (test/*)
1 parent 00d60e4 commit e031a74

6 files changed

+23
-25
lines changed

.lintrunner.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ include_patterns = [
302302
'profiler/**/*.py',
303303
'runtime/**/*.py',
304304
'scripts/**/*.py',
305-
# 'test/**/*.py',
305+
'test/**/*.py',
306306
'util/**/*.py',
307307
'*.py',
308308
]

.mypy.ini

+10
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@ files =
2121
profiler,
2222
runtime,
2323
scripts,
24+
test,
2425
util
2526

2627
mypy_path = executorch
2728

29+
[mypy-executorch.backends.*]
30+
follow_untyped_imports = True
31+
2832
[mypy-executorch.codegen.*]
2933
follow_untyped_imports = True
3034

@@ -46,6 +50,12 @@ follow_untyped_imports = True
4650
[mypy-executorch.runtime.*]
4751
follow_untyped_imports = True
4852

53+
[mypy-executorch.test.*]
54+
follow_untyped_imports = True
55+
56+
[mypy-functorch.*]
57+
follow_untyped_imports = True
58+
4959
[mypy-requests.*]
5060
follow_untyped_imports = True
5161

test/end2end/exported_module.py

+6-14
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,7 @@ def return_wrapper():
126126
trace_inputs_method = "get_upper_bound_inputs"
127127
get_trace_inputs = get_inputs_adapter(
128128
(
129-
# pyre-fixme[6]: For 1st argument expected `(...) -> Any` but got
130-
# `Union[Module, Tensor]`.
131-
getattr(eager_module, trace_inputs_method)
129+
getattr(eager_module, trace_inputs_method) # type: ignore[arg-type]
132130
if hasattr(eager_module, trace_inputs_method)
133131
else eager_module.get_random_inputs
134132
),
@@ -144,18 +142,14 @@ def return_wrapper():
144142
if hasattr(eager_module, "get_dynamic_shapes"):
145143
assert capture_config is not None
146144
assert capture_config.enable_aot is True
147-
# pyre-fixme[29]: `Union[nn.modules.module.Module,
148-
# torch._tensor.Tensor]` is not a function.
149-
trace_dynamic_shapes = eager_module.get_dynamic_shapes()
145+
trace_dynamic_shapes = eager_module.get_dynamic_shapes() # type: ignore[operator]
150146
method_name_to_dynamic_shapes = {}
151147
for method in methods:
152148
method_name_to_dynamic_shapes[method] = trace_dynamic_shapes
153149

154150
memory_planning_pass = MemoryPlanningPass()
155151
if hasattr(eager_module, "get_memory_planning_pass"):
156-
# pyre-fixme[29]: `Union[nn.modules.module.Module,
157-
# torch._tensor.Tensor]` is not a function.
158-
memory_planning_pass = eager_module.get_memory_planning_pass()
152+
memory_planning_pass = eager_module.get_memory_planning_pass() # type: ignore[operator]
159153

160154
class WrapperModule(nn.Module):
161155
def __init__(self, method):
@@ -172,7 +166,7 @@ def __init__(self, method):
172166
assert method_name == "forward"
173167
ep = _export(
174168
eager_module,
175-
method_input,
169+
method_input, # type: ignore[arg-type]
176170
dynamic_shapes=(
177171
method_name_to_dynamic_shapes[method_name]
178172
if method_name_to_dynamic_shapes
@@ -184,7 +178,7 @@ def __init__(self, method):
184178
else:
185179
exported_methods[method_name] = export(
186180
eager_module,
187-
method_input,
181+
method_input, # type: ignore[arg-type]
188182
dynamic_shapes=(
189183
method_name_to_dynamic_shapes[method_name]
190184
if method_name_to_dynamic_shapes
@@ -220,9 +214,7 @@ def __init__(self, method):
220214

221215
# Get a function that creates random inputs appropriate for testing.
222216
get_random_inputs_fn = get_inputs_adapter(
223-
# pyre-fixme[6]: For 1st argument expected `(...) -> Any` but got
224-
# `Union[Module, Tensor]`.
225-
eager_module.get_random_inputs,
217+
eager_module.get_random_inputs, # type: ignore[arg-type]
226218
# all exported methods must have the same signature so just pick the first one.
227219
methods[0],
228220
)

test/end2end/test_end2end.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@
5252
kernel_mode = None # either aten mode or lean mode
5353
try:
5454
from executorch.extension.pybindings.portable_lib import (
55-
_load_bundled_program_from_buffer,
5655
_load_for_executorch_from_buffer,
57-
_load_for_executorch_from_bundled_program,
5856
)
5957

6058
kernel_mode = "lean"
@@ -63,10 +61,8 @@
6361
pass
6462

6563
try:
66-
from executorch.extension.pybindings.aten_lib import (
67-
_load_bundled_program_from_buffer,
64+
from executorch.extension.pybindings.aten_lib import ( # type: ignore[import-not-found]
6865
_load_for_executorch_from_buffer,
69-
_load_for_executorch_from_bundled_program,
7066
)
7167

7268
assert kernel_mode is None

test/models/export_delegated_program.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,7 @@ def export_module_to_program(
118118
eager_module = module_class().eval()
119119
inputs = ()
120120
if hasattr(eager_module, "get_random_inputs"):
121-
# pyre-fixme[29]: `Union[nn.modules.module.Module, torch._tensor.Tensor]` is
122-
# not a function.
123-
inputs = eager_module.get_random_inputs()
121+
inputs = eager_module.get_random_inputs() # type: ignore[operator]
124122

125123
class WrapperModule(torch.nn.Module):
126124
def __init__(self, fn):
@@ -153,7 +151,7 @@ def forward(self, *args, **kwargs):
153151
).to_executorch(config=et_config)
154152
else:
155153
edge: exir.EdgeProgramManager = to_edge(exported_program)
156-
lowered_module = to_backend(
154+
lowered_module = to_backend( # type: ignore[call-arg]
157155
backend_id, edge.exported_program(), compile_specs=[]
158156
)
159157

test/models/generate_linear_out_bundled_program.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
from executorch.exir.passes import MemoryPlanningPass, ToOutVarPass
2828
from executorch.exir.print_program import pretty_print
2929

30-
from executorch.test.models.linear_model import LinearModel
30+
from executorch.test.models.linear_model import ( # type: ignore[import-not-found]
31+
LinearModel,
32+
)
3133
from torch.export import export
3234

3335

0 commit comments

Comments
 (0)