We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Undefined names in Python code found with flake8
## Description


## Way to reproduce
[flake8](http://flake8.pycqa.org) testing of https://github.com/scikit-image/scikit-image on Python 3.7.1

$ __flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics__
```
./skimage/measure/mc_meta/createluts.py:139:18: F821 undefined name 'luts'
    for a in dir(luts):
                 ^
./doc/ext/notebook_doc.py:1:1: F822 undefined name 'python_to_notebook' in __all__
__all__ = ['python_to_notebook', 'Notebook']
^
1     F821 undefined name 'luts'
1     F822 undefined name 'python_to_notebook' in __all__
2
```
__E901,E999,F821,F822,F823__ are the "_showstopper_" [flake8](http://flake8.pycqa.org) issues that can halt the runtime with a SyntaxError, NameError, etc. These 5 are different from most other flake8 issues which are merely "style violations" -- useful for readability but they do not effect runtime safety.
* F821: undefined name `name`
* F822: undefined name `name` in `__all__`
* F823: local variable name referenced before assignment
* E901: SyntaxError or IndentationError
* E999: SyntaxError -- failed to compile a file into an Abstract Syntax Tree


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `doc/ext/notebook_doc.py`
Content:
```
1 __all__ = ['python_to_notebook', 'Notebook']
2 
3 import json
4 import copy
5 import warnings
6 
7 
8 # Skeleton notebook in JSON format
9 skeleton_nb = """{
10     "metadata": {
11     "name":""
12     },
13     "nbformat": 3,
14     "nbformat_minor": 0,
15     "worksheets": [
16         {
17             "cells": [
18             {
19                 "cell_type": "code",
20                 "collapsed": false,
21                 "input": [
22                     "%matplotlib inline"
23                 ],
24                 "language": "python",
25                 "metadata": {},
26                 "outputs": []
27             }
28             ],
29           "metadata": {}
30         }
31     ]
32 }"""
33 
34 
35 class Notebook(object):
36     """
37     Notebook object for building an IPython notebook cell-by-cell.
38     """
39 
40     def __init__(self):
41         # cell type code
42         self.cell_code = {
43             'cell_type': 'code',
44             'collapsed': False,
45             'input': [
46                 '# Code Goes Here'
47             ],
48             'language': 'python',
49             'metadata': {},
50             'outputs': []
51         }
52 
53         # cell type markdown
54         self.cell_md = {
55             'cell_type': 'markdown',
56             'metadata': {},
57             'source': [
58                 'Markdown Goes Here'
59             ]
60         }
61 
62         self.template = json.loads(skeleton_nb)
63         self.cell_type = {'input': self.cell_code, 'source': self.cell_md}
64         self.valuetype_to_celltype = {'code': 'input', 'markdown': 'source'}
65 
66     def add_cell(self, value, cell_type='code'):
67         """Add a notebook cell.
68 
69         Parameters
70         ----------
71         value : str
72             Cell content.
73         cell_type : {'code', 'markdown'}
74             Type of content (default is 'code').
75 
76         """
77         if cell_type in ['markdown', 'code']:
78             key = self.valuetype_to_celltype[cell_type]
79             cells = self.template['worksheets'][0]['cells']
80             cells.append(copy.deepcopy(self.cell_type[key]))
81             # assign value to the last cell
82             cells[-1][key] = value
83         else:
84             warnings.warn('Ignoring unsupported cell type (%s)' % cell_type)
85 
86     def json(self):
87         """Return a JSON representation of the notebook.
88 
89         Returns
90         -------
91         str
92             JSON notebook.
93 
94         """
95         return json.dumps(self.template, indent=2)
96 
97 
98
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/doc/ext/notebook_doc.py b/doc/ext/notebook_doc.py
--- a/doc/ext/notebook_doc.py
+++ b/doc/ext/notebook_doc.py
@@ -1,4 +1,4 @@
-__all__ = ['python_to_notebook', 'Notebook']
+__all__ = ['Notebook']
 
 import json
 import copy

{"golden_diff": "diff --git a/doc/ext/notebook_doc.py b/doc/ext/notebook_doc.py\n--- a/doc/ext/notebook_doc.py\n+++ b/doc/ext/notebook_doc.py\n@@ -1,4 +1,4 @@\n-__all__ = ['python_to_notebook', 'Notebook']\n+__all__ = ['Notebook']\n \n import json\n import copy\n", "issue": "Undefined names in Python code found with flake8\n## Description\r\n\r\n\r\n## Way to reproduce\r\n[flake8](http://flake8.pycqa.org) testing of https://github.com/scikit-image/scikit-image on Python 3.7.1\r\n\r\n$ __flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics__\r\n```\r\n./skimage/measure/mc_meta/createluts.py:139:18: F821 undefined name 'luts'\r\n    for a in dir(luts):\r\n                 ^\r\n./doc/ext/notebook_doc.py:1:1: F822 undefined name 'python_to_notebook' in __all__\r\n__all__ = ['python_to_notebook', 'Notebook']\r\n^\r\n1     F821 undefined name 'luts'\r\n1     F822 undefined name 'python_to_notebook' in __all__\r\n2\r\n```\r\n__E901,E999,F821,F822,F823__ are the \"_showstopper_\" [flake8](http://flake8.pycqa.org) issues that can halt the runtime with a SyntaxError, NameError, etc. These 5 are different from most other flake8 issues which are merely \"style violations\" -- useful for readability but they do not effect runtime safety.\r\n* F821: undefined name `name`\r\n* F822: undefined name `name` in `__all__`\r\n* F823: local variable name referenced before assignment\r\n* E901: SyntaxError or IndentationError\r\n* E999: SyntaxError -- failed to compile a file into an Abstract Syntax Tree\r\n\n", "before_files": [{"content": "__all__ = ['python_to_notebook', 'Notebook']\n\nimport json\nimport copy\nimport warnings\n\n\n# Skeleton notebook in JSON format\nskeleton_nb = \"\"\"{\n    \"metadata\": {\n    \"name\":\"\"\n    },\n    \"nbformat\": 3,\n    \"nbformat_minor\": 0,\n    \"worksheets\": [\n        {\n            \"cells\": [\n            {\n                \"cell_type\": \"code\",\n                \"collapsed\": false,\n                \"input\": [\n                    \"%matplotlib inline\"\n                ],\n                \"language\": \"python\",\n                \"metadata\": {},\n                \"outputs\": []\n            }\n            ],\n          \"metadata\": {}\n        }\n    ]\n}\"\"\"\n\n\nclass Notebook(object):\n    \"\"\"\n    Notebook object for building an IPython notebook cell-by-cell.\n    \"\"\"\n\n    def __init__(self):\n        # cell type code\n        self.cell_code = {\n            'cell_type': 'code',\n            'collapsed': False,\n            'input': [\n                '# Code Goes Here'\n            ],\n            'language': 'python',\n            'metadata': {},\n            'outputs': []\n        }\n\n        # cell type markdown\n        self.cell_md = {\n            'cell_type': 'markdown',\n            'metadata': {},\n            'source': [\n                'Markdown Goes Here'\n            ]\n        }\n\n        self.template = json.loads(skeleton_nb)\n        self.cell_type = {'input': self.cell_code, 'source': self.cell_md}\n        self.valuetype_to_celltype = {'code': 'input', 'markdown': 'source'}\n\n    def add_cell(self, value, cell_type='code'):\n        \"\"\"Add a notebook cell.\n\n        Parameters\n        ----------\n        value : str\n            Cell content.\n        cell_type : {'code', 'markdown'}\n            Type of content (default is 'code').\n\n        \"\"\"\n        if cell_type in ['markdown', 'code']:\n            key = self.valuetype_to_celltype[cell_type]\n            cells = self.template['worksheets'][0]['cells']\n            cells.append(copy.deepcopy(self.cell_type[key]))\n            # assign value to the last cell\n            cells[-1][key] = value\n        else:\n            warnings.warn('Ignoring unsupported cell type (%s)' % cell_type)\n\n    def json(self):\n        \"\"\"Return a JSON representation of the notebook.\n\n        Returns\n        -------\n        str\n            JSON notebook.\n\n        \"\"\"\n        return json.dumps(self.template, indent=2)\n\n\n", "path": "doc/ext/notebook_doc.py"}], "after_files": [{"content": "__all__ = ['Notebook']\n\nimport json\nimport copy\nimport warnings\n\n\n# Skeleton notebook in JSON format\nskeleton_nb = \"\"\"{\n    \"metadata\": {\n    \"name\":\"\"\n    },\n    \"nbformat\": 3,\n    \"nbformat_minor\": 0,\n    \"worksheets\": [\n        {\n            \"cells\": [\n            {\n                \"cell_type\": \"code\",\n                \"collapsed\": false,\n                \"input\": [\n                    \"%matplotlib inline\"\n                ],\n                \"language\": \"python\",\n                \"metadata\": {},\n                \"outputs\": []\n            }\n            ],\n          \"metadata\": {}\n        }\n    ]\n}\"\"\"\n\n\nclass Notebook(object):\n    \"\"\"\n    Notebook object for building an IPython notebook cell-by-cell.\n    \"\"\"\n\n    def __init__(self):\n        # cell type code\n        self.cell_code = {\n            'cell_type': 'code',\n            'collapsed': False,\n            'input': [\n                '# Code Goes Here'\n            ],\n            'language': 'python',\n            'metadata': {},\n            'outputs': []\n        }\n\n        # cell type markdown\n        self.cell_md = {\n            'cell_type': 'markdown',\n            'metadata': {},\n            'source': [\n                'Markdown Goes Here'\n            ]\n        }\n\n        self.template = json.loads(skeleton_nb)\n        self.cell_type = {'input': self.cell_code, 'source': self.cell_md}\n        self.valuetype_to_celltype = {'code': 'input', 'markdown': 'source'}\n\n    def add_cell(self, value, cell_type='code'):\n        \"\"\"Add a notebook cell.\n\n        Parameters\n        ----------\n        value : str\n            Cell content.\n        cell_type : {'code', 'markdown'}\n            Type of content (default is 'code').\n\n        \"\"\"\n        if cell_type in ['markdown', 'code']:\n            key = self.valuetype_to_celltype[cell_type]\n            cells = self.template['worksheets'][0]['cells']\n            cells.append(copy.deepcopy(self.cell_type[key]))\n            # assign value to the last cell\n            cells[-1][key] = value\n        else:\n            warnings.warn('Ignoring unsupported cell type (%s)' % cell_type)\n\n    def json(self):\n        \"\"\"Return a JSON representation of the notebook.\n\n        Returns\n        -------\n        str\n            JSON notebook.\n\n        \"\"\"\n        return json.dumps(self.template, indent=2)\n\n\n", "path": "doc/ext/notebook_doc.py"}]}