Skip to content

Commit e3b8c79

Browse files
committed
Fixing lint errors
1 parent 775d888 commit e3b8c79

2 files changed

Lines changed: 25 additions & 29 deletions

File tree

d8s_python/ast_data.py

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# TODO: all of these functions where code_text is given should also be able to read a file at a given path (?)
88

99

10-
def _python_ast_exception_name(node: Union[ast.Raise, ast.ExceptHandler]) -> str:
10+
def _python_ast_exception_name(node: Union[ast.Raise, ast.ExceptHandler]) -> str: # noqa: CCR001
1111
"""."""
1212
if hasattr(node, 'exc') and node.exc: # this handles ast.Raise nodes
1313
if hasattr(
@@ -41,38 +41,34 @@ def _python_ast_exception_name(node: Union[ast.Raise, ast.ExceptHandler]) -> str
4141

4242
def python_ast_raise_name(node: ast.Raise) -> Optional[str]:
4343
"""Get the name of the exception raise by the given ast.Raise object."""
44-
if isinstance(node, ast.Raise):
45-
return _python_ast_exception_name(node)
44+
return _python_ast_exception_name(node)
4645

4746

4847
def python_ast_exception_handler_exceptions_handled(handler: ast.ExceptHandler) -> Optional[Iterable[str]]:
4948
"""Return all of the exceptions handled by the given exception handler."""
50-
if isinstance(handler, ast.ExceptHandler):
51-
handler_has_multiple_exceptions = handler.type and hasattr(handler.type, 'elts')
52-
if handler_has_multiple_exceptions:
53-
yield from (_python_ast_exception_name(i) for i in handler.type.elts)
54-
else:
55-
exception_name = _python_ast_exception_name(handler)
56-
if exception_name:
57-
yield exception_name
49+
handler_has_multiple_exceptions = handler.type and hasattr(handler.type, 'elts')
50+
if handler_has_multiple_exceptions:
51+
yield from (_python_ast_exception_name(i) for i in handler.type.elts)
52+
else:
53+
exception_name = _python_ast_exception_name(handler)
54+
if exception_name:
55+
yield exception_name
5856

5957

6058
def python_ast_exception_handler_exceptions_raised(handler: ast.ExceptHandler) -> Optional[Iterable[str]]:
6159
"""Return the exception raised by the given exception handler."""
62-
if isinstance(handler, ast.ExceptHandler):
63-
raise_nodes = list(python_ast_objects_of_type(handler, ast.Raise))
64-
if any(raise_nodes):
65-
exceptions_names = list(map(python_ast_raise_name, raise_nodes))
66-
for name in exceptions_names:
67-
if name and name == handler.name:
68-
exceptions_names = iterable_replace(
69-
exceptions_names, name, python_ast_exception_handler_exceptions_handled(handler)
70-
)
71-
elif name is None:
72-
exceptions_names = iterable_replace(
73-
exceptions_names, name, python_ast_exception_handler_exceptions_handled(handler)
74-
)
75-
yield from more_itertools.collapse(exceptions_names, base_type=str)
60+
raise_nodes = python_ast_objects_of_type(handler, ast.Raise)
61+
exceptions_names = list(map(python_ast_raise_name, raise_nodes))
62+
for name in exceptions_names:
63+
if name and name == handler.name:
64+
exceptions_names = iterable_replace(
65+
exceptions_names, name, python_ast_exception_handler_exceptions_handled(handler)
66+
)
67+
elif name is None:
68+
exceptions_names = iterable_replace(
69+
exceptions_names, name, python_ast_exception_handler_exceptions_handled(handler)
70+
)
71+
yield from more_itertools.collapse(exceptions_names, base_type=str)
7672

7773

7874
def python_exceptions_handled(code_text: str) -> Iterable[str]:
@@ -145,7 +141,7 @@ def _python_ast_clean(code_text: str) -> str:
145141

146142

147143
# TODO: have a decorator to parse a first argument that is a string
148-
def python_ast_objects_of_type(
144+
def python_ast_objects_of_type( # noqa: CCR001
149145
code_text_or_ast_object: Union[str, object], ast_type: type, *, recursive_search: bool = True
150146
) -> Iterable[object]:
151147
"""Return all of the ast objects of the given ast_type in the code_text_or_ast_object."""

d8s_python/python_data.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def python_clean(code_text: str) -> str:
9494
return code_text
9595

9696

97-
def python_function_blocks(
97+
def python_function_blocks( # noqa: CCR001
9898
code_text: str, *, ignore_private_functions: bool = False, ignore_nested_functions: bool = False
9999
) -> List[str]:
100100
"""Find the code (as a string) for every function in the given code_text."""
@@ -206,7 +206,7 @@ def python_keywords() -> List[str]:
206206

207207

208208
# @decorators.map_first_arg
209-
def python_object_properties_enumerate(
209+
def python_object_properties_enumerate( # noqa: CCR001
210210
python_object: Any, *, run_methods: bool = True, internal_properties: bool = True
211211
) -> None:
212212
"""Enumerate and print out the properties of the given object."""
@@ -248,7 +248,7 @@ def python_copy_shallow(python_object: Any) -> Any:
248248

249249

250250
# @decorators.map_first_arg
251-
def python_file_names(path: str, *, exclude_tests: bool = False) -> List[str]:
251+
def python_file_names(path: str, *, exclude_tests: bool = False) -> List[str]: # noqa: CCR001
252252
"""Find all python files in the given directory."""
253253
from d8s_file_system import directory_file_names_matching
254254

0 commit comments

Comments
 (0)