Django version is 3.2.9.
Python version is 3.10.0.
And typing_extensions 3.10.0.2
I'm new to coding, python, etc., and can't figure out what is the problem. Following django tutorial I created an app and ran the server successfully, but a day later, when I tried to do that again I faced this problem:
File "C:\Users\fused\Desktop\code\py\myproject\myapp\views.py", line 1, in <module>
from typing_extensions import Required
ImportError: cannot import name 'Required' from 'typing_extensions' (C:\Users\fused\AppData\Local\Programs\Python\Python310\lib\site-packages\typing_extensions.py)
After trying to run a server with 'python manage.py runserver' this problem appeared, tried reinstalling typing_extensions, checked versions of everything, but nothing solved the problem.
If any additional information is needed, I'll reply with it. Thanks in advance
Support for Required
and NotRequired
have been added to typing_extensions
version 4.0.0 as experimental features.
Everything should work for now like it's stated in PEP 655.
It seems like Required
and NotRequired
aren't implemented yet in typing_extensions
.
PEP 655 states:
The goal is to be able to make the following statement:
The mypy type checker supports Required and NotRequired. A reference implementation of the runtime component is provided in the typing_extensions module.
It's just the goal — it isn't the current state. It is neither listed in typing_extensions
' README nor does it appear in the source code.
I think it is really confusing that vscode's pylance/pyright can resolve typing_extensions.Required
and typing_extensions.NotRequired
, even though it isn't implemented in the module.
As a workaround you could try to replace from typing_extensions import Required
with
try:
from typing_extensions import Required
except ImportError:
from typing import Generic, TypeVar
T = TypeVar("T")
class Required(Generic[T]):
pass
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With