@@ -61,8 +61,8 @@ def get_function_args(node: ast.FunctionDef) -> Tuple[List[Any], List[Any]]:
61
61
Returns:
62
62
(non_optional_args, optional_args): named function args
63
63
"""
64
- assert (
65
- type ( node ) == ast .FunctionDef
64
+ assert isinstance (
65
+ node , ast .FunctionDef
66
66
), "Incorrect node type. Expected ast.FunctionDef, got {}" .format (type (node ))
67
67
total_args = len (node .args .args )
68
68
default_args = len (node .args .defaults )
@@ -95,15 +95,17 @@ def check_class_definition(python_path: str, node: ast.ClassDef) -> None:
95
95
Returns:
96
96
None
97
97
"""
98
- assert (
99
- type ( node ) == ast .ClassDef
98
+ assert isinstance (
99
+ node , ast .ClassDef
100
100
), "Received invalid node type. Expected ClassDef, got: {}" .format (type (node ))
101
101
102
102
is_TorchRec_module = False
103
103
is_test_file = "tests" in python_path
104
104
for base in node .bases :
105
105
# 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
107
109
continue
108
110
109
111
# 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:
164
166
functions : Dict [str , Tuple [List [Any ], List [Any ]]] = {}
165
167
function_sub_nodes = {}
166
168
for sub_node in node .body :
167
- if type (sub_node ) == ast .FunctionDef :
169
+ if isinstance (sub_node , ast .FunctionDef ) :
168
170
assert isinstance (sub_node , ast .FunctionDef )
169
171
functions [sub_node .name ] = get_function_args (sub_node )
170
172
function_sub_nodes [sub_node .name ] = sub_node
@@ -310,7 +312,7 @@ def linter_one_file(python_path: str) -> None:
310
312
python_path = python_path .strip ()
311
313
try :
312
314
for node in ast .parse (read_file (python_path )).body :
313
- if type (node ) == ast .ClassDef :
315
+ if isinstance (node , ast .ClassDef ) :
314
316
assert isinstance (node , ast .ClassDef )
315
317
check_class_definition (python_path , node )
316
318
except SyntaxError as e : # pragma: nocover
0 commit comments