We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Uncaught exception: TypeError: Protocols cannot be instantiated
### Summary

TypeError: Protocols cannot be instantiated in 1.12.0
After upgrading from 1.11.1 to 1.12.0, streamlit server keeps raising exceptions and clients get stuck at loading page 'please wait...'

### Steps to reproduce

server error snippet:

```
Traceback (most recent call last):
  File "/home/xx/.local/lib/python3.9/site-packages/tornado/http1connection.py", line 276, in _read_message
    delegate.finish()
  File "/home/xx/.local/lib/python3.9/site-packages/tornado/routing.py", line 268, in finish
    self.delegate.finish()
  File "/home/xx/.local/lib/python3.9/site-packages/tornado/web.py", line 2322, in finish
    self.execute()
  File "/home/xx/.local/lib/python3.9/site-packages/tornado/web.py", line 2344, in execute
    self.handler = self.handler_class(
  File "/home/xx/.local/lib/python3.9/site-packages/tornado/websocket.py", line 224, in __init__
    super().__init__(application, request, **kwargs)
  File "/home/xx/.local/lib/python3.9/site-packages/tornado/web.py", line 215, in __init__
    super().__init__()
  File "/usr/local/python3/lib/python3.9/typing.py", line 1083, in _no_init
    raise TypeError('Protocols cannot be instantiated')
TypeError: Protocols cannot be instantiated
```

**Actual behavior:**

Get stuck at loading page 'please wait...' 

### Debug info

- Streamlit version: 1.12.0
- Python version: 3.9.7
- Using Conda? PipEnv? PyEnv? Pex? using venv
- OS version: Debian 10  
- Browser version: Chrome 104 and Safari 15

### Additional information

Roll back to streamlit version 1.11.1, everything works fine.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `lib/setup.py`
Content:
```
1 # Copyright 2018-2022 Streamlit Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #    http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 import os
16 import setuptools
17 import sys
18 
19 from setuptools.command.install import install
20 
21 
22 VERSION = "1.12.0"  # PEP-440
23 
24 NAME = "streamlit"
25 
26 DESCRIPTION = "The fastest way to build data apps in Python"
27 
28 LONG_DESCRIPTION = (
29     "Streamlit's open-source app framework is the easiest way "
30     "for data scientists and machine learning engineers to "
31     "create beautiful, performant apps in only a few hours! "
32     "All in pure Python. All for free."
33 )
34 
35 # IMPORTANT: We should try very hard *not* to add dependencies to Streamlit.
36 # And if you do add one, make the required version as general as possible.
37 # But include relevant lower bounds for any features we use from our dependencies.
38 INSTALL_REQUIRES = [
39     "altair>=3.2.0",
40     "blinker>=1.0.0",
41     "cachetools>=4.0",
42     "click>=7.0",
43     # 1.4 introduced the functionality found in python 3.8's importlib.metadata module
44     "importlib-metadata>=1.4",
45     "numpy",
46     "packaging>=14.1",
47     "pandas>=0.21.0",
48     "pillow>=6.2.0",
49     "protobuf<4,>=3.12",
50     "pyarrow>=4.0",
51     "pydeck>=0.1.dev5",
52     "pympler>=0.9",
53     "python-dateutil",
54     "requests>=2.4",
55     "rich>=10.11.0",
56     "semver",
57     "toml",
58     # 5.0 has a fix for etag header: https://github.com/tornadoweb/tornado/issues/2262
59     "tornado>=5.0",
60     "typing-extensions>=3.10.0.0",
61     "tzlocal>=1.1",
62     "validators>=0.2",
63     # Don't require watchdog on MacOS, since it'll fail without xcode tools.
64     # Without watchdog, we fallback to a polling file watcher to check for app changes.
65     "watchdog; platform_system != 'Darwin'",
66 ]
67 
68 # We want to exclude some dependencies in our internal conda distribution of
69 # Streamlit.
70 CONDA_OPTIONAL_DEPENDENCIES = [
71     "gitpython!=3.1.19",
72 ]
73 
74 # NOTE: ST_CONDA_BUILD is used here (even though CONDA_BUILD is set
75 # automatically when using the `conda build` command) because the
76 # `load_setup_py_data()` conda build helper function does not have the
77 # CONDA_BUILD environment variable set when it runs to generate our build
78 # recipe from meta.yaml.
79 if not os.getenv("ST_CONDA_BUILD"):
80     INSTALL_REQUIRES.extend(CONDA_OPTIONAL_DEPENDENCIES)
81 
82 
83 class VerifyVersionCommand(install):
84     """Custom command to verify that the git tag matches our version"""
85 
86     description = "verify that the git tag matches our version"
87 
88     def run(self):
89         tag = os.getenv("CIRCLE_TAG")
90 
91         if tag != VERSION:
92             info = "Git tag: {0} does not match the version of this app: {1}".format(
93                 tag, VERSION
94             )
95             sys.exit(info)
96 
97 
98 setuptools.setup(
99     name=NAME,
100     version=VERSION,
101     description=DESCRIPTION,
102     long_description=LONG_DESCRIPTION,
103     url="https://streamlit.io",
104     project_urls={
105         "Source": "https://github.com/streamlit/streamlit",
106     },
107     author="Streamlit Inc",
108     author_email="hello@streamlit.io",
109     python_requires=">=3.7",
110     license="Apache 2",
111     # PEP 561: https://mypy.readthedocs.io/en/stable/installed_packages.html
112     package_data={"streamlit": ["py.typed", "hello/**/*.py"]},
113     packages=setuptools.find_packages(exclude=["tests", "tests.*"]),
114     # Requirements
115     install_requires=INSTALL_REQUIRES,
116     zip_safe=False,  # install source files not egg
117     include_package_data=True,  # copy html and friends
118     entry_points={"console_scripts": ["streamlit = streamlit.web.cli:main"]},
119     # For Windows so that streamlit * commands work ie.
120     # - streamlit version
121     # - streamlit hello
122     scripts=["bin/streamlit.cmd"],
123     cmdclass={
124         "verify": VerifyVersionCommand,
125     },
126 )
127
```
--- 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/lib/setup.py b/lib/setup.py
--- a/lib/setup.py
+++ b/lib/setup.py
@@ -106,7 +106,10 @@
     },
     author="Streamlit Inc",
     author_email="hello@streamlit.io",
-    python_requires=">=3.7",
+    # We exclude Python 3.9.7 from our compatible versions due to a bug in that version
+    # with typing.Protocol. See https://github.com/streamlit/streamlit/issues/5140 and
+    # https://bugs.python.org/issue45121
+    python_requires=">=3.7, !=3.9.7",
     license="Apache 2",
     # PEP 561: https://mypy.readthedocs.io/en/stable/installed_packages.html
     package_data={"streamlit": ["py.typed", "hello/**/*.py"]},

{"golden_diff": "diff --git a/lib/setup.py b/lib/setup.py\n--- a/lib/setup.py\n+++ b/lib/setup.py\n@@ -106,7 +106,10 @@\n     },\n     author=\"Streamlit Inc\",\n     author_email=\"hello@streamlit.io\",\n-    python_requires=\">=3.7\",\n+    # We exclude Python 3.9.7 from our compatible versions due to a bug in that version\n+    # with typing.Protocol. See https://github.com/streamlit/streamlit/issues/5140 and\n+    # https://bugs.python.org/issue45121\n+    python_requires=\">=3.7, !=3.9.7\",\n     license=\"Apache 2\",\n     # PEP 561: https://mypy.readthedocs.io/en/stable/installed_packages.html\n     package_data={\"streamlit\": [\"py.typed\", \"hello/**/*.py\"]},\n", "issue": "Uncaught exception: TypeError: Protocols cannot be instantiated\n### Summary\r\n\r\nTypeError: Protocols cannot be instantiated in 1.12.0\r\nAfter upgrading from 1.11.1 to 1.12.0, streamlit server keeps raising exceptions and clients get stuck at loading page 'please wait...'\r\n\r\n### Steps to reproduce\r\n\r\nserver error snippet:\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"/home/xx/.local/lib/python3.9/site-packages/tornado/http1connection.py\", line 276, in _read_message\r\n    delegate.finish()\r\n  File \"/home/xx/.local/lib/python3.9/site-packages/tornado/routing.py\", line 268, in finish\r\n    self.delegate.finish()\r\n  File \"/home/xx/.local/lib/python3.9/site-packages/tornado/web.py\", line 2322, in finish\r\n    self.execute()\r\n  File \"/home/xx/.local/lib/python3.9/site-packages/tornado/web.py\", line 2344, in execute\r\n    self.handler = self.handler_class(\r\n  File \"/home/xx/.local/lib/python3.9/site-packages/tornado/websocket.py\", line 224, in __init__\r\n    super().__init__(application, request, **kwargs)\r\n  File \"/home/xx/.local/lib/python3.9/site-packages/tornado/web.py\", line 215, in __init__\r\n    super().__init__()\r\n  File \"/usr/local/python3/lib/python3.9/typing.py\", line 1083, in _no_init\r\n    raise TypeError('Protocols cannot be instantiated')\r\nTypeError: Protocols cannot be instantiated\r\n```\r\n\r\n**Actual behavior:**\r\n\r\nGet stuck at loading page 'please wait...' \r\n\r\n### Debug info\r\n\r\n- Streamlit version: 1.12.0\r\n- Python version: 3.9.7\r\n- Using Conda? PipEnv? PyEnv? Pex? using venv\r\n- OS version: Debian 10  \r\n- Browser version: Chrome 104 and Safari 15\r\n\r\n### Additional information\r\n\r\nRoll back to streamlit version 1.11.1, everything works fine.\r\n\n", "before_files": [{"content": "# Copyright 2018-2022 Streamlit Inc.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport os\nimport setuptools\nimport sys\n\nfrom setuptools.command.install import install\n\n\nVERSION = \"1.12.0\"  # PEP-440\n\nNAME = \"streamlit\"\n\nDESCRIPTION = \"The fastest way to build data apps in Python\"\n\nLONG_DESCRIPTION = (\n    \"Streamlit's open-source app framework is the easiest way \"\n    \"for data scientists and machine learning engineers to \"\n    \"create beautiful, performant apps in only a few hours! \"\n    \"All in pure Python. All for free.\"\n)\n\n# IMPORTANT: We should try very hard *not* to add dependencies to Streamlit.\n# And if you do add one, make the required version as general as possible.\n# But include relevant lower bounds for any features we use from our dependencies.\nINSTALL_REQUIRES = [\n    \"altair>=3.2.0\",\n    \"blinker>=1.0.0\",\n    \"cachetools>=4.0\",\n    \"click>=7.0\",\n    # 1.4 introduced the functionality found in python 3.8's importlib.metadata module\n    \"importlib-metadata>=1.4\",\n    \"numpy\",\n    \"packaging>=14.1\",\n    \"pandas>=0.21.0\",\n    \"pillow>=6.2.0\",\n    \"protobuf<4,>=3.12\",\n    \"pyarrow>=4.0\",\n    \"pydeck>=0.1.dev5\",\n    \"pympler>=0.9\",\n    \"python-dateutil\",\n    \"requests>=2.4\",\n    \"rich>=10.11.0\",\n    \"semver\",\n    \"toml\",\n    # 5.0 has a fix for etag header: https://github.com/tornadoweb/tornado/issues/2262\n    \"tornado>=5.0\",\n    \"typing-extensions>=3.10.0.0\",\n    \"tzlocal>=1.1\",\n    \"validators>=0.2\",\n    # Don't require watchdog on MacOS, since it'll fail without xcode tools.\n    # Without watchdog, we fallback to a polling file watcher to check for app changes.\n    \"watchdog; platform_system != 'Darwin'\",\n]\n\n# We want to exclude some dependencies in our internal conda distribution of\n# Streamlit.\nCONDA_OPTIONAL_DEPENDENCIES = [\n    \"gitpython!=3.1.19\",\n]\n\n# NOTE: ST_CONDA_BUILD is used here (even though CONDA_BUILD is set\n# automatically when using the `conda build` command) because the\n# `load_setup_py_data()` conda build helper function does not have the\n# CONDA_BUILD environment variable set when it runs to generate our build\n# recipe from meta.yaml.\nif not os.getenv(\"ST_CONDA_BUILD\"):\n    INSTALL_REQUIRES.extend(CONDA_OPTIONAL_DEPENDENCIES)\n\n\nclass VerifyVersionCommand(install):\n    \"\"\"Custom command to verify that the git tag matches our version\"\"\"\n\n    description = \"verify that the git tag matches our version\"\n\n    def run(self):\n        tag = os.getenv(\"CIRCLE_TAG\")\n\n        if tag != VERSION:\n            info = \"Git tag: {0} does not match the version of this app: {1}\".format(\n                tag, VERSION\n            )\n            sys.exit(info)\n\n\nsetuptools.setup(\n    name=NAME,\n    version=VERSION,\n    description=DESCRIPTION,\n    long_description=LONG_DESCRIPTION,\n    url=\"https://streamlit.io\",\n    project_urls={\n        \"Source\": \"https://github.com/streamlit/streamlit\",\n    },\n    author=\"Streamlit Inc\",\n    author_email=\"hello@streamlit.io\",\n    python_requires=\">=3.7\",\n    license=\"Apache 2\",\n    # PEP 561: https://mypy.readthedocs.io/en/stable/installed_packages.html\n    package_data={\"streamlit\": [\"py.typed\", \"hello/**/*.py\"]},\n    packages=setuptools.find_packages(exclude=[\"tests\", \"tests.*\"]),\n    # Requirements\n    install_requires=INSTALL_REQUIRES,\n    zip_safe=False,  # install source files not egg\n    include_package_data=True,  # copy html and friends\n    entry_points={\"console_scripts\": [\"streamlit = streamlit.web.cli:main\"]},\n    # For Windows so that streamlit * commands work ie.\n    # - streamlit version\n    # - streamlit hello\n    scripts=[\"bin/streamlit.cmd\"],\n    cmdclass={\n        \"verify\": VerifyVersionCommand,\n    },\n)\n", "path": "lib/setup.py"}], "after_files": [{"content": "# Copyright 2018-2022 Streamlit Inc.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\nimport os\nimport setuptools\nimport sys\n\nfrom setuptools.command.install import install\n\n\nVERSION = \"1.12.0\"  # PEP-440\n\nNAME = \"streamlit\"\n\nDESCRIPTION = \"The fastest way to build data apps in Python\"\n\nLONG_DESCRIPTION = (\n    \"Streamlit's open-source app framework is the easiest way \"\n    \"for data scientists and machine learning engineers to \"\n    \"create beautiful, performant apps in only a few hours! \"\n    \"All in pure Python. All for free.\"\n)\n\n# IMPORTANT: We should try very hard *not* to add dependencies to Streamlit.\n# And if you do add one, make the required version as general as possible.\n# But include relevant lower bounds for any features we use from our dependencies.\nINSTALL_REQUIRES = [\n    \"altair>=3.2.0\",\n    \"blinker>=1.0.0\",\n    \"cachetools>=4.0\",\n    \"click>=7.0\",\n    # 1.4 introduced the functionality found in python 3.8's importlib.metadata module\n    \"importlib-metadata>=1.4\",\n    \"numpy\",\n    \"packaging>=14.1\",\n    \"pandas>=0.21.0\",\n    \"pillow>=6.2.0\",\n    \"protobuf<4,>=3.12\",\n    \"pyarrow>=4.0\",\n    \"pydeck>=0.1.dev5\",\n    \"pympler>=0.9\",\n    \"python-dateutil\",\n    \"requests>=2.4\",\n    \"rich>=10.11.0\",\n    \"semver\",\n    \"toml\",\n    # 5.0 has a fix for etag header: https://github.com/tornadoweb/tornado/issues/2262\n    \"tornado>=5.0\",\n    \"typing-extensions>=3.10.0.0\",\n    \"tzlocal>=1.1\",\n    \"validators>=0.2\",\n    # Don't require watchdog on MacOS, since it'll fail without xcode tools.\n    # Without watchdog, we fallback to a polling file watcher to check for app changes.\n    \"watchdog; platform_system != 'Darwin'\",\n]\n\n# We want to exclude some dependencies in our internal conda distribution of\n# Streamlit.\nCONDA_OPTIONAL_DEPENDENCIES = [\n    \"gitpython!=3.1.19\",\n]\n\n# NOTE: ST_CONDA_BUILD is used here (even though CONDA_BUILD is set\n# automatically when using the `conda build` command) because the\n# `load_setup_py_data()` conda build helper function does not have the\n# CONDA_BUILD environment variable set when it runs to generate our build\n# recipe from meta.yaml.\nif not os.getenv(\"ST_CONDA_BUILD\"):\n    INSTALL_REQUIRES.extend(CONDA_OPTIONAL_DEPENDENCIES)\n\n\nclass VerifyVersionCommand(install):\n    \"\"\"Custom command to verify that the git tag matches our version\"\"\"\n\n    description = \"verify that the git tag matches our version\"\n\n    def run(self):\n        tag = os.getenv(\"CIRCLE_TAG\")\n\n        if tag != VERSION:\n            info = \"Git tag: {0} does not match the version of this app: {1}\".format(\n                tag, VERSION\n            )\n            sys.exit(info)\n\n\nsetuptools.setup(\n    name=NAME,\n    version=VERSION,\n    description=DESCRIPTION,\n    long_description=LONG_DESCRIPTION,\n    url=\"https://streamlit.io\",\n    project_urls={\n        \"Source\": \"https://github.com/streamlit/streamlit\",\n    },\n    author=\"Streamlit Inc\",\n    author_email=\"hello@streamlit.io\",\n    # We exclude Python 3.9.7 from our compatible versions due to a bug in that version\n    # with typing.Protocol. See https://github.com/streamlit/streamlit/issues/5140 and\n    # https://bugs.python.org/issue45121\n    python_requires=\">=3.7, !=3.9.7\",\n    license=\"Apache 2\",\n    # PEP 561: https://mypy.readthedocs.io/en/stable/installed_packages.html\n    package_data={\"streamlit\": [\"py.typed\", \"hello/**/*.py\"]},\n    packages=setuptools.find_packages(exclude=[\"tests\", \"tests.*\"]),\n    # Requirements\n    install_requires=INSTALL_REQUIRES,\n    zip_safe=False,  # install source files not egg\n    include_package_data=True,  # copy html and friends\n    entry_points={\"console_scripts\": [\"streamlit = streamlit.web.cli:main\"]},\n    # For Windows so that streamlit * commands work ie.\n    # - streamlit version\n    # - streamlit hello\n    scripts=[\"bin/streamlit.cmd\"],\n    cmdclass={\n        \"verify\": VerifyVersionCommand,\n    },\n)\n", "path": "lib/setup.py"}]}