From f052816d56faf026e59a4297bede247bc436fbc0 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Sun, 19 Jun 2022 18:07:28 +0100 Subject: [PATCH] Fix TypedDict on new Python and typing_extensions (#86) --- typing_inspect.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/typing_inspect.py b/typing_inspect.py index 9f31bfe..33dca6b 100644 --- a/typing_inspect.py +++ b/typing_inspect.py @@ -16,8 +16,13 @@ if (3, 4, 0) <= sys.version_info[:3] < (3, 9, 2): from typing_extensions import _TypedDictMeta as _TypedDictMeta_TE elif sys.version_info[:3] >= (3, 9, 2): - # typing_extensions.TypedDict is a re-export from typing. - from typing import _TypedDictMeta as _TypedDictMeta_TE + # Situation with typing_extensions.TypedDict is complicated. + # Use the one defined in typing_extentions, and if there is none, + # fall back to typing. + try: + from typing_extensions import _TypedDictMeta as _TypedDictMeta_TE + except ImportError: + from typing import _TypedDictMeta as _TypedDictMeta_TE else: # typing_extensions.TypedDict is a re-export from typing. from typing import TypedDict