# Buggy code
def _check_nested_function(self, node: AnyFunctionDef) -> None:
    parent = getattr(node, "parent", None)
    is_inside_function = isinstance(parent, self._function_nodes)

    if is_inside_function and node.name not in NESTED_FUNCTIONS_WHITELIST:
        self.add_violation(NestedFunctionViolation(node, text=node.name))


# Traceback (AttributeError)
multiprocessing.pool.RemoteTraceback:
"""
Traceback (most recent call last):
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/multiprocessing/pool.py", line 119, in worker
result = (True, func(*args, **kwds))
File "/Users/sobolev/Documents/PyCharmProjects/rostelecom_svetochka/.venv/lib/python3.6/site-packages/flake8/checker.py", line 648, in _run_checks
return checker.run_checks()
File "/Users/sobolev/Documents/PyCharmProjects/rostelecom_svetochka/.venv/lib/python3.6/site-packages/flake8/checker.py", line 579, in run_checks
self.run_ast_checks()
File "/Users/sobolev/Documents/PyCharmProjects/rostelecom_svetochka/.venv/lib/python3.6/site-packages/flake8/checker.py", line 486, in run_ast_checks
checker = self.run_check(plugin, tree=ast)
File "/Users/sobolev/Documents/PyCharmProjects/rostelecom_svetochka/.venv/lib/python3.6/site-packages/flake8/checker.py", line 435, in run_check
return plugin['plugin'](**arguments)
File "/Users/sobolev/Documents/PyCharmProjects/rostelecom_svetochka/.venv/lib/python3.6/site-packages/flake8/plugins/pyflakes.py", line 91, in __init__
withDoctest=with_doctest)
File "/Users/sobolev/Documents/PyCharmProjects/rostelecom_svetochka/.venv/lib/python3.6/site-packages/pyflakes/checker.py", line 495, in __init__
self.runDeferred(self._deferredFunctions)
File "/Users/sobolev/Documents/PyCharmProjects/rostelecom_svetochka/.venv/lib/python3.6/site-packages/pyflakes/checker.py", line 532, in runDeferred
handler()
File "/Users/sobolev/Documents/PyCharmProjects/rostelecom_svetochka/.venv/lib/python3.6/site-packages/pyflakes/checker.py", line 1172, in runFunction
self.handleNode(stmt, node)
File "/Users/sobolev/Documents/PyCharmProjects/rostelecom_svetochka/.venv/lib/python3.6/site-packages/pyflakes/checker.py", line 863, in handleNode
handler(node)
File "/Users/sobolev/Documents/PyCharmProjects/rostelecom_svetochka/.venv/lib/python3.6/site-packages/pyflakes/checker.py", line 1310, in TRY
self.handleNode(child, node)
File "/Users/sobolev/Documents/PyCharmProjects/rostelecom_svetochka/.venv/lib/python3.6/site-packages/pyflakes/checker.py", line 863, in handleNode
handler(node)
File "/Users/sobolev/Documents/PyCharmProjects/rostelecom_svetochka/.venv/lib/python3.6/site-packages/pyflakes/checker.py", line 816, in handleChildren
self.handleNode(node, tree)
File "/Users/sobolev/Documents/PyCharmProjects/rostelecom_svetochka/.venv/lib/python3.6/site-packages/pyflakes/checker.py", line 863, in handleNode
handler(node)
File "/Users/sobolev/Documents/PyCharmProjects/rostelecom_svetochka/.venv/lib/python3.6/site-packages/pyflakes/checker.py", line 816, in handleChildren
self.handleNode(node, tree)
File "/Users/sobolev/Documents/PyCharmProjects/rostelecom_svetochka/.venv/lib/python3.6/site-packages/pyflakes/checker.py", line 863, in handleNode
handler(node)
File "/Users/sobolev/Documents/PyCharmProjects/rostelecom_svetochka/.venv/lib/python3.6/site-packages/pyflakes/checker.py", line 1048, in NAME
self.handleNodeStore(node)
File "/Users/sobolev/Documents/PyCharmProjects/rostelecom_svetochka/.venv/lib/python3.6/site-packages/pyflakes/checker.py", line 782, in handleNodeStore
self.addBinding(node, binding)
File "/Users/sobolev/Documents/PyCharmProjects/rostelecom_svetochka/.venv/lib/python3.6/site-packages/pyflakes/checker.py", line 665, in addBinding
if existing and not self.differentForks(node, existing.source):
File "/Users/sobolev/Documents/PyCharmProjects/rostelecom_svetochka/.venv/lib/python3.6/site-packages/pyflakes/checker.py", line 647, in differentForks
if self.descendantOf(lnode, items, ancestor) ^ \
File "/Users/sobolev/Documents/PyCharmProjects/rostelecom_svetochka/.venv/lib/python3.6/site-packages/pyflakes/checker.py", line 637, in descendantOf
if self.getCommonAncestor(node, a, stop):
File "/Users/sobolev/Documents/PyCharmProjects/rostelecom_svetochka/.venv/lib/python3.6/site-packages/pyflakes/checker.py", line 629, in getCommonAncestor
if (lnode.depth > rnode.depth):
AttributeError: 'ExceptHandler' object has no attribute 'depth'
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/Users/sobolev/Documents/PyCharmProjects/rostelecom_svetochka/.venv/bin/flake8", line 11, in <module>
sys.exit(main())
File "/Users/sobolev/Documents/PyCharmProjects/rostelecom_svetochka/.venv/lib/python3.6/site-packages/flake8/main/cli.py", line 16, in main
app.run(argv)
File "/Users/sobolev/Documents/PyCharmProjects/rostelecom_svetochka/.venv/lib/python3.6/site-packages/flake8/main/application.py", line 396, in run
self._run(argv)
File "/Users/sobolev/Documents/PyCharmProjects/rostelecom_svetochka/.venv/lib/python3.6/site-packages/flake8/main/application.py", line 384, in _run
self.run_checks()
File "/Users/sobolev/Documents/PyCharmProjects/rostelecom_svetochka/.venv/lib/python3.6/site-packages/flake8/main/application.py", line 310, in run_checks
self.file_checker_manager.run()
File "/Users/sobolev/Documents/PyCharmProjects/rostelecom_svetochka/.venv/lib/python3.6/site-packages/flake8/checker.py", line 319, in run
self.run_parallel()
File "/Users/sobolev/Documents/PyCharmProjects/rostelecom_svetochka/.venv/lib/python3.6/site-packages/flake8/checker.py", line 288, in run_parallel
for ret in pool_map:
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/multiprocessing/pool.py", line 735, in next
raise value
AttributeError: 'ExceptHandler' object has no attribute 'depth'

# Fixed code
def _check_nested_function(self, node: AnyFunctionDef) -> None:
    parent = getattr(node, "wps_parent", None)
    is_inside_function = isinstance(parent, self._function_nodes)

    if is_inside_function and node.name not in NESTED_FUNCTIONS_WHITELIST:
        self.add_violation(NestedFunctionViolation(node, text=node.name))