Repository: streamlit/streamlit

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.



Discussion:
Can confirm:

**Debug info**
- Streamlit version: 1.12.0
- Python version: 3.9.7
- Using Conda? PipEnv? PyEnv? Pex?: I use venv
- OS version: macOS 12.4, Apple M1 Pro
- Browser version: Chrome 104.0.5112.79
Same problem here
- Streamlit 1.12
- Running `python:3.9-slim` Docker image
- Mac OS 12.1, M1
Hi all! I'll add this to a list of things for us to look into in our team meeting on Monday, but if I'm remembering correctly, I think this particular issue may actually be caused by a bug that was introduced specifically in Python 3.9.7 (we weren't using `typing.Protocol` until streamlit 1.12.0, which is why the bug didn't surface in streamlit until now), so upgrading to a newer patch version of Python 3.9 should fix the issue.

Depending on the prevalence of the issue and whether or not most users are easily able to upgrade their Python versions, we may decide to fix this in a workaround, but there's also a chance that we'll choose not to do so given that the root-cause of the issue is in Python and not streamlit (my personal preference would be to not work around this in streamlit and encourage people to upgrade their Python versions if possible, but we're aware that doing so isn't always practical so will take that into consideration). I'll keep this issue updated once the team is able to discuss it.
Confirmed that upgrading from Python 3.9.7 to 3.9.12 fixes the issue! 🎉 
I upgrade python version to 3.9.12 but I'm still having error(TypeError: Protocols cannot be instantiated) Is there something that I can try or check with?

streamlit version -1.12.0
Os version -Window 10

Also had this issue before and upgrading to 3.9.12 fixed it. 
I have upgraded today to 1.12.0 (from 1.11.1), and I'm having the same problem:

```
File "/home/xxx/anaconda3/lib/python3.9/typing.py", line 1083, in _no_init
    raise TypeError('Protocols cannot be instantiated')
TypeError: Protocols cannot be instantiated
My environment is Python 3.9.7 and Ubuntu 18.04.6 LTS.
```

With Streamlit 1.11.1 all is working OK, but upgrading to 1.12.0 gives me the above error.

The **solution for me was upgrading to Python 3.9.12**, now it is all working OK with Streamlit 1.12.0.
@vdonato I am not sure if the solution should be related to `python` version; Streamlit should have some `integration` tests on multiple `python` versions in-placed to avoid this type of regressions.

Can you clarify the final solution here if a bug-fix patch will be released for `streamlit`; or the user needs to upgrade the python version? Thanks

The reason I asked is, upgrading python env. of a production env. is not as easy as upgrading a local python version. and I need to know so I can plan accordingly

Resolving patch:
diff --git a/lib/setup.py b/lib/setup.py
--- a/lib/setup.py
+++ b/lib/setup.py
@@ -106,7 +106,10 @@ def run(self):
     },
     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"]},


Test patch: