Method: pylint.checkers.utils.is_from_fallback_block
Calls: 1489, Exceptions: 19, Paths: 3Back
Path 1: 1435 calls (0.96)
ImportFrom (740) Import (695)
False (1435)
1def is_from_fallback_block(node: nodes.NodeNG) -> bool:
2 """Check if the given node is from a fallback import block."""
3 context = find_try_except_wrapper_node(node)
4 if not context:
5 return False
6
7 if isinstance(context, nodes.ExceptHandler):
8 other_body = context.parent.body
9 handlers = context.parent.handlers
10 else:
11 other_body = itertools.chain.from_iterable(
12 handler.body for handler in context.handlers
13 )
14 handlers = context.handlers
15
16 has_fallback_imports = any(
17 isinstance(import_node, (nodes.ImportFrom, nodes.Import))
18 for import_node in other_body
19 )
20 ignores_import_error = _except_handlers_ignores_exceptions(
21 handlers, (ImportError, ModuleNotFoundError)
22 )
23 return ignores_import_error or has_fallback_imports
Path 2: 44 calls (0.03)
Import (34) ImportFrom (10)
True (34) False (10)
GeneratorExit (9)
1def is_from_fallback_block(node: nodes.NodeNG) -> bool:
2 """Check if the given node is from a fallback import block."""
3 context = find_try_except_wrapper_node(node)
4 if not context:
5 return False
6
7 if isinstance(context, nodes.ExceptHandler):
8 other_body = context.parent.body
9 handlers = context.parent.handlers
10 else:
11 other_body = itertools.chain.from_iterable(
12 handler.body for handler in context.handlers
13 )
14 handlers = context.handlers
15
16 has_fallback_imports = any(
17 isinstance(import_node, (nodes.ImportFrom, nodes.Import))
18 for import_node in other_body
19 )
20 ignores_import_error = _except_handlers_ignores_exceptions(
21 handlers, (ImportError, ModuleNotFoundError)
22 )
23 return ignores_import_error or has_fallback_imports
Path 3: 10 calls (0.01)
ImportFrom (6) Import (4)
True (10)
GeneratorExit (10)
1def is_from_fallback_block(node: nodes.NodeNG) -> bool:
2 """Check if the given node is from a fallback import block."""
3 context = find_try_except_wrapper_node(node)
4 if not context:
5 return False
6
7 if isinstance(context, nodes.ExceptHandler):
8 other_body = context.parent.body
9 handlers = context.parent.handlers
10 else:
11 other_body = itertools.chain.from_iterable(
12 handler.body for handler in context.handlers
13 )
14 handlers = context.handlers
15
16 has_fallback_imports = any(
17 isinstance(import_node, (nodes.ImportFrom, nodes.Import))
18 for import_node in other_body
19 )
20 ignores_import_error = _except_handlers_ignores_exceptions(
21 handlers, (ImportError, ModuleNotFoundError)
22 )
23 return ignores_import_error or has_fallback_imports