From 8ad46284b9b12af43d542f4751975c4d5911e1ef Mon Sep 17 00:00:00 2001 From: hs_junxiang Date: Mon, 11 Sep 2023 15:29:48 +0800 Subject: Fix: `TypedDict` from `typing` error #886 Ref: https://github.com/python/typeshed/issues/3500 --- g4f/typing.py | 10 ++++++++-- requirements.txt | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/g4f/typing.py b/g4f/typing.py index 02386037..5f63c222 100644 --- a/g4f/typing.py +++ b/g4f/typing.py @@ -1,4 +1,10 @@ -from typing import Any, AsyncGenerator, Generator, NewType, Tuple, TypedDict, Union +import sys +from typing import Any, AsyncGenerator, Generator, NewType, Tuple, Union + +if sys.version_info >= (3, 8): + from typing import TypedDict +else: + from typing_extensions import TypedDict SHA256 = NewType('sha_256_hash', str) CreateResult = Generator[str, None, None] @@ -11,4 +17,4 @@ __all__ = [ 'TypedDict', 'SHA256', 'CreateResult', -] \ No newline at end of file +] diff --git a/requirements.txt b/requirements.txt index 76431391..7ee6e37c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,3 +9,4 @@ js2py quickjs flask flask-cors +typing-extensions -- cgit v1.2.3