Skip to content

Commit 92278a0

Browse files
aliafzalmeta-codesync[bot]
authored andcommitted
Code Quality fix [E721] [2/n] (#3411)
Summary: Pull Request resolved: #3411 [E721] compare types, for exact checks use `is` / `is not`, for instance checks use `isinstance()` See https://www.flake8rules.com/rules/E721.htmlArcLint(FLAKE8) Reviewed By: TroyGarden Differential Revision: D83734895 fbshipit-source-id: 8924c791c321f87856e5314c7e61131bb2d09637
1 parent bec09cd commit 92278a0

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

torchrec/linter/module_linter.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ def get_function_args(node: ast.FunctionDef) -> Tuple[List[Any], List[Any]]:
6161
Returns:
6262
(non_optional_args, optional_args): named function args
6363
"""
64-
assert (
65-
type(node) == ast.FunctionDef
64+
assert isinstance(
65+
node, ast.FunctionDef
6666
), "Incorrect node type. Expected ast.FunctionDef, got {}".format(type(node))
6767
total_args = len(node.args.args)
6868
default_args = len(node.args.defaults)
@@ -95,15 +95,17 @@ def check_class_definition(python_path: str, node: ast.ClassDef) -> None:
9595
Returns:
9696
None
9797
"""
98-
assert (
99-
type(node) == ast.ClassDef
98+
assert isinstance(
99+
node, ast.ClassDef
100100
), "Received invalid node type. Expected ClassDef, got: {}".format(type(node))
101101

102102
is_TorchRec_module = False
103103
is_test_file = "tests" in python_path
104104
for base in node.bases:
105105
# For now only names and attributes are supported
106-
if type(base) != ast.Name and type(base) != ast.Attribute: # pragma: nocover
106+
if not isinstance(base, ast.Name) and not isinstance(
107+
base, ast.Attribute
108+
): # pragma: nocover
107109
continue
108110

109111
# We assume that TorchRec module has one of the following inheritance patterns:
@@ -164,7 +166,7 @@ def check_class_definition(python_path: str, node: ast.ClassDef) -> None:
164166
functions: Dict[str, Tuple[List[Any], List[Any]]] = {}
165167
function_sub_nodes = {}
166168
for sub_node in node.body:
167-
if type(sub_node) == ast.FunctionDef:
169+
if isinstance(sub_node, ast.FunctionDef):
168170
assert isinstance(sub_node, ast.FunctionDef)
169171
functions[sub_node.name] = get_function_args(sub_node)
170172
function_sub_nodes[sub_node.name] = sub_node
@@ -310,7 +312,7 @@ def linter_one_file(python_path: str) -> None:
310312
python_path = python_path.strip()
311313
try:
312314
for node in ast.parse(read_file(python_path)).body:
313-
if type(node) == ast.ClassDef:
315+
if isinstance(node, ast.ClassDef):
314316
assert isinstance(node, ast.ClassDef)
315317
check_class_definition(python_path, node)
316318
except SyntaxError as e: # pragma: nocover

0 commit comments

Comments
 (0)