Skip to content

Commit 4753100

Browse files
samestepfacebook-github-bot
authored andcommitted
Un-ignore F403 in .flake8 (pytorch#55838)
Summary: Generally wildcard imports are bad for the reasons described here: https://www.flake8rules.com/rules/F403.html This PR replaces wildcard imports with an explicit list of imported items where possible, and adds a `# noqa: F403` comment in the other cases (mostly re-exports in `__init__.py` files). This is a prerequisite for pytorch#55816, because currently [`tools/codegen/dest/register_dispatch_key.py` simply fails if you sort its imports](https://github.com/pytorch/pytorch/actions/runs/742505908). Pull Request resolved: pytorch#55838 Test Plan: CI. You can also run `flake8` locally. Reviewed By: jbschlosser Differential Revision: D27724232 Pulled By: samestep fbshipit-source-id: 269fb09cb4168f8a51fd65bfaacc6cda7fb87c34
1 parent 75eb026 commit 4753100

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+250
-123
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ max-line-length = 120
44
# C408 ignored because we like the dict keyword argument syntax
55
# E501 is not flexible enough, we're using B950 instead
66
ignore =
7-
E203,E305,E402,E501,E721,E741,F403,F405,F821,F841,F999,W503,W504,C408,E302,W291,E303,
7+
E203,E305,E402,E501,E721,E741,F405,F821,F841,F999,W503,W504,C408,E302,W291,E303,
88
# shebang has extra meaning in fbcode lints, so I think it's not worth trying
99
# to line this up with executable bit
1010
EXE001,

benchmarks/fastrnns/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from .cells import *
2-
from .factory import *
1+
from .cells import * # noqa: F403
2+
from .factory import * # noqa: F403
33

44
# (output, next_state) = cell(input, state)
55
seqLength = 100

benchmarks/fastrnns/runner.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
import torch
44
import torchvision.models as cnn
55

6-
from .factory import *
6+
from .factory import (dropoutlstm_creator, imagenet_cnn_creator,
7+
layernorm_pytorch_lstm_creator, lnlstm_creator,
8+
lstm_creator, lstm_multilayer_creator,
9+
lstm_premul_bias_creator, lstm_premul_creator,
10+
lstm_simple_creator, pytorch_lstm_creator,
11+
varlen_lstm_creator, varlen_pytorch_lstm_creator)
712

813

914
class DisableCuDNN():

test/jit/test_hooks.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
import os
22
import sys
33
import unittest
4+
from typing import Tuple
45

56
import torch
6-
from jit.test_hooks_modules import *
7+
from jit.test_hooks_modules import (
8+
ModuleDirectFowardSubmodCall, ModuleForwardSingleInput,
9+
ModuleForwardTupleInput, create_forward_tuple_input,
10+
create_module_forward_multiple_inputs, create_module_forward_single_input,
11+
create_module_hook_return_nothing,
12+
create_module_multiple_hooks_multiple_inputs,
13+
create_module_multiple_hooks_single_input, create_module_no_forward_input,
14+
create_module_same_hook_repeated, create_submodule_forward_multiple_inputs,
15+
create_submodule_forward_single_input,
16+
create_submodule_forward_single_input_return_not_tupled,
17+
create_submodule_hook_return_nothing,
18+
create_submodule_multiple_hooks_multiple_inputs,
19+
create_submodule_multiple_hooks_single_input,
20+
create_submodule_no_forward_input, create_submodule_same_hook_repeated,
21+
create_submodule_to_call_directly_with_hooks)
722

823
# Make the helper files in test/ importable
924
pytorch_test_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))

test/jit_hooks/model.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,18 @@
66
# grab modules from test_jit_hooks.cpp
77
pytorch_test_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
88
sys.path.append(pytorch_test_dir)
9-
from jit.test_hooks_modules import *
9+
from jit.test_hooks_modules import (
10+
create_forward_tuple_input, create_module_forward_multiple_inputs,
11+
create_module_forward_single_input, create_module_hook_return_nothing,
12+
create_module_multiple_hooks_multiple_inputs,
13+
create_module_multiple_hooks_single_input, create_module_no_forward_input,
14+
create_module_same_hook_repeated, create_submodule_forward_multiple_inputs,
15+
create_submodule_forward_single_input,
16+
create_submodule_hook_return_nothing,
17+
create_submodule_multiple_hooks_multiple_inputs,
18+
create_submodule_multiple_hooks_single_input,
19+
create_submodule_same_hook_repeated,
20+
create_submodule_to_call_directly_with_hooks)
1021

1122
# Create saved modules for JIT forward hooks and pre-hooks
1223
def main():

test/mobile/test_lite_script_module.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import torch
22
import torch.utils.bundled_inputs
3-
from torch.utils.mobile_optimizer import *
3+
from torch.utils.mobile_optimizer import optimize_for_mobile
44
import io
5-
from typing import NamedTuple
5+
from typing import Dict, List, NamedTuple
66
from collections import namedtuple
77

88
from torch.jit.mobile import _load_for_lite_interpreter, _export_operator_list

test/onnx/model_defs/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .squeezenet import *
2-
from .super_resolution import *
3-
from .op_test import *
4-
from .srresnet import *
1+
from .squeezenet import * # noqa: F403
2+
from .super_resolution import * # noqa: F403
3+
from .op_test import * # noqa: F403
4+
from .srresnet import * # noqa: F403

test/onnx/test_pytorch_common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
pytorch_test_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
99
sys.path.insert(-1, pytorch_test_dir)
1010

11-
from torch.testing._internal.common_utils import * # noqa: F401
11+
from torch.testing._internal.common_utils import * # noqa: F401,F403
1212

1313
torch.set_default_tensor_type('torch.FloatTensor')
1414

test/test_jit_fuser_legacy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22
sys.argv.append("--jit_executor=legacy")
3-
from test_jit_fuser import *
3+
from test_jit_fuser import * # noqa: F403
44

55
if __name__ == '__main__':
66
run_tests()

test/test_jit_legacy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sys
22
sys.argv.append("--jit_executor=legacy")
3-
from test_jit import *
3+
from test_jit import * # noqa: F403
44

55
if __name__ == '__main__':
66
run_tests()

0 commit comments

Comments
 (0)