# Buggy code
def _is_node_return_ended(node):
    """Check if the node ends with an explicit return statement.

    Args:
        node (astroid.NodeNG): node to be checked.

    Returns:
        bool: True if the node ends with an explicit statement, False otherwise.

    """
    # Recursion base case
    if isinstance(node, astroid.Return):
        return True
    if isinstance(node, astroid.Raise):
        # a Raise statement doesn't need to end with a return statement
        # but if the exception raised is handled, then the handler has to
        # ends with a return statement
        exc = utils.safe_infer(node.exc)
        if exc is None or exc is astroid.Uninferable:
            return False
        exc_name = exc.pytype().split(".")[-1]
        handlers = utils.get_exception_handlers(node, exc_name)
        if handlers:
            # among all the handlers handling the exception at least one
            # must end with a return statement
            return any(_is_node_return_ended(_handler) for _handler in handlers)
        # if no handlers handle the exception then it's ok
        return True
    if isinstance(node, astroid.If):
        # if statement is returning if there are exactly two return statements in its
        # children : one for the body part, the other for the orelse part
        return_stmts = [_is_node_return_ended(_child) for _child in node.get_children()]
        return sum(return_stmts) == 2
    # recurses on the children of the node except for those which are except handler
    # because one cannot be sure that the handler will really be used
    return any(
        _is_node_return_ended(_child)
        for _child in node.get_children()
        if not isinstance(_child, astroid.ExceptHandler)
    )


# Traceback (AttributeError)
$ pylint pylint_test.py
No config file found, using default configuration
************* Module pylint_test
C:  1, 0: Missing module docstring (missing-docstring)
C:  1, 0: Missing class docstring (missing-docstring)
C:  4, 0: Missing function docstring (missing-docstring)
W:  6, 8: Using a conditional statement with a constant value (using-constant-test)
Traceback (most recent call last):
File "/usr/local/bin/pylint", line 11, in <module>
sys.exit(run_pylint())
File "/usr/local/lib/python3.6/site-packages/pylint/__init__.py", line 16, in run_pylint
Run(sys.argv[1:])
File "/usr/local/lib/python3.6/site-packages/pylint/lint.py", line 1347, in __init__
linter.check(args)
File "/usr/local/lib/python3.6/site-packages/pylint/lint.py", line 768, in check
self._do_check(files_or_modules)
File "/usr/local/lib/python3.6/site-packages/pylint/lint.py", line 901, in _do_check
self.check_astroid_module(ast_node, walker, rawcheckers, tokencheckers)
File "/usr/local/lib/python3.6/site-packages/pylint/lint.py", line 980, in check_astroid_module
walker.walk(ast_node)
File "/usr/local/lib/python3.6/site-packages/pylint/utils.py", line 1014, in walk
self.walk(child)
File "/usr/local/lib/python3.6/site-packages/pylint/utils.py", line 1016, in walk
cb(astroid)
File "/usr/local/lib/python3.6/site-packages/pylint/checkers/refactoring.py", line 357, in leave_functiondef
self._check_consistent_returns(node)
File "/usr/local/lib/python3.6/site-packages/pylint/checkers/refactoring.py", line 560, in _check_consistent_returns
and _is_node_return_ended(node)):
File "/usr/local/lib/python3.6/site-packages/pylint/checkers/refactoring.py", line 73, in _is_node_return_ended
return any(_is_node_return_ended(_child) for _child in node.get_children()
File "/usr/local/lib/python3.6/site-packages/pylint/checkers/refactoring.py", line 74, in <genexpr>
if not isinstance(_child, astroid.ExceptHandler))
File "/usr/local/lib/python3.6/site-packages/pylint/checkers/refactoring.py", line 73, in _is_node_return_ended
return any(_is_node_return_ended(_child) for _child in node.get_children()
File "/usr/local/lib/python3.6/site-packages/pylint/checkers/refactoring.py", line 74, in <genexpr>
if not isinstance(_child, astroid.ExceptHandler))
File "/usr/local/lib/python3.6/site-packages/pylint/checkers/refactoring.py", line 69, in _is_node_return_ended
return_stmts = [_is_node_return_ended(_child) for _child in node.get_children()]
File "/usr/local/lib/python3.6/site-packages/pylint/checkers/refactoring.py", line 69, in <listcomp>
return_stmts = [_is_node_return_ended(_child) for _child in node.get_children()]
File "/usr/local/lib/python3.6/site-packages/pylint/checkers/refactoring.py", line 63, in _is_node_return_ended
return any(_is_node_return_ended(_handler) for _handler in handlers)
File "/usr/local/lib/python3.6/site-packages/pylint/checkers/refactoring.py", line 63, in <genexpr>
return any(_is_node_return_ended(_handler) for _handler in handlers)
File "/usr/local/lib/python3.6/site-packages/pylint/checkers/refactoring.py", line 73, in _is_node_return_ended
return any(_is_node_return_ended(_child) for _child in node.get_children()
File "/usr/local/lib/python3.6/site-packages/pylint/checkers/refactoring.py", line 74, in <genexpr>
if not isinstance(_child, astroid.ExceptHandler))
File "/usr/local/lib/python3.6/site-packages/pylint/checkers/refactoring.py", line 55, in _is_node_return_ended
exc = utils.safe_infer(node.exc)
File "/usr/local/lib/python3.6/site-packages/pylint/checkers/utils.py", line 806, in safe_infer
inferit = node.infer(context=context)
AttributeError: 'NoneType' object has no attribute 'infer'

# Fixed code
def _is_node_return_ended(node):
    """Check if the node ends with an explicit return statement.

    Args:
        node (astroid.NodeNG): node to be checked.

    Returns:
        bool: True if the node ends with an explicit statement, False otherwise.

    """
    # Recursion base case
    if isinstance(node, astroid.Return):
        return True
    if isinstance(node, astroid.Raise):
        # a Raise statement doesn't need to end with a return statement
        # but if the exception raised is handled, then the handler has to
        # ends with a return statement
        if not node.exc:
            # Ignore bare raises
            return True
        exc = utils.safe_infer(node.exc)
        if exc is None or exc is astroid.Uninferable:
            return False
        exc_name = exc.pytype().split(".")[-1]
        handlers = utils.get_exception_handlers(node, exc_name)
        if handlers:
            # among all the handlers handling the exception at least one
            # must end with a return statement
            return any(_is_node_return_ended(_handler) for _handler in handlers)
        # if no handlers handle the exception then it's ok
        return True
    if isinstance(node, astroid.If):
        # if statement is returning if there are exactly two return statements in its
        # children : one for the body part, the other for the orelse part
        return_stmts = [_is_node_return_ended(_child) for _child in node.get_children()]
        return sum(return_stmts) == 2
    # recurses on the children of the node except for those which are except handler
    # because one cannot be sure that the handler will really be used
    return any(
        _is_node_return_ended(_child)
        for _child in node.get_children()
        if not isinstance(_child, astroid.ExceptHandler)
    )