Path 1: 3171 calls (0.98)

AssignName (3171)

False (3171)

1def _redefines_import(node: nodes.AssignName) -> bool:
2    """Detect that the given node (AssignName) is inside an
3    exception handler and redefines an import from the tryexcept body.
4
5    Returns True if the node redefines an import, False otherwise.
6    """
7    current = node
8    while current and not isinstance(current.parent, nodes.ExceptHandler):
9        current = current.parent
10    if not current or not utils.error_of_type(current.parent, ImportError):
11        return False
12    try_block = current.parent.parent
13    for import_node in try_block.nodes_of_class((nodes.ImportFrom, nodes.Import)):
14        for name, alias in import_node.names:
15            if alias:
16                if alias == node.name:
17                    return True
18            elif name == node.name:
19                return True
20    return False
            

Path 2: 44 calls (0.01)

AssignName (44)

False (44)

1def _redefines_import(node: nodes.AssignName) -> bool:
2    """Detect that the given node (AssignName) is inside an
3    exception handler and redefines an import from the tryexcept body.
4
5    Returns True if the node redefines an import, False otherwise.
6    """
7    current = node
8    while current and not isinstance(current.parent, nodes.ExceptHandler):
9        current = current.parent
10    if not current or not utils.error_of_type(current.parent, ImportError):
11        return False
12    try_block = current.parent.parent
13    for import_node in try_block.nodes_of_class((nodes.ImportFrom, nodes.Import)):
14        for name, alias in import_node.names:
15            if alias:
16                if alias == node.name:
17                    return True
18            elif name == node.name:
19                return True
20    return False
            

Path 3: 4 calls (0.0)

AssignName (4)

True (4)

1def _redefines_import(node: nodes.AssignName) -> bool:
2    """Detect that the given node (AssignName) is inside an
3    exception handler and redefines an import from the tryexcept body.
4
5    Returns True if the node redefines an import, False otherwise.
6    """
7    current = node
8    while current and not isinstance(current.parent, nodes.ExceptHandler):
9        current = current.parent
10    if not current or not utils.error_of_type(current.parent, ImportError):
11        return False
12    try_block = current.parent.parent
13    for import_node in try_block.nodes_of_class((nodes.ImportFrom, nodes.Import)):
14        for name, alias in import_node.names:
15            if alias:
16                if alias == node.name:
17                    return True
18            elif name == node.name:
19                return True
20    return False
            

Path 4: 3 calls (0.0)

AssignName (3)

False (3)

1def _redefines_import(node: nodes.AssignName) -> bool:
2    """Detect that the given node (AssignName) is inside an
3    exception handler and redefines an import from the tryexcept body.
4
5    Returns True if the node redefines an import, False otherwise.
6    """
7    current = node
8    while current and not isinstance(current.parent, nodes.ExceptHandler):
9        current = current.parent
10    if not current or not utils.error_of_type(current.parent, ImportError):
11        return False
12    try_block = current.parent.parent
13    for import_node in try_block.nodes_of_class((nodes.ImportFrom, nodes.Import)):
14        for name, alias in import_node.names:
15            if alias:
16                if alias == node.name:
17                    return True
18            elif name == node.name:
19                return True
20    return False
            

Path 5: 1 calls (0.0)

AssignName (1)

True (1)

1def _redefines_import(node: nodes.AssignName) -> bool:
2    """Detect that the given node (AssignName) is inside an
3    exception handler and redefines an import from the tryexcept body.
4
5    Returns True if the node redefines an import, False otherwise.
6    """
7    current = node
8    while current and not isinstance(current.parent, nodes.ExceptHandler):
9        current = current.parent
10    if not current or not utils.error_of_type(current.parent, ImportError):
11        return False
12    try_block = current.parent.parent
13    for import_node in try_block.nodes_of_class((nodes.ImportFrom, nodes.Import)):
14        for name, alias in import_node.names:
15            if alias:
16                if alias == node.name:
17                    return True
18            elif name == node.name:
19                return True
20    return False