26
26
ExtensionsTypedDict = None
27
27
28
28
try :
29
- from typing_extensions import _TypedDictMeta as ExtensionsTypedDictMeta
29
+ from typing_extensions import is_typeddict
30
30
except ImportError :
31
- ExtensionsTypedDictMeta = None
31
+ assert sys .version_info >= (3 , 10 )
32
+ from typing import is_typeddict
32
33
33
34
__all__ = [
34
35
"ExtensionsTypedDict" ,
@@ -176,9 +177,8 @@ def get_final_base(type) -> Optional[type]:
176
177
from typing_extensions import get_origin as te_get_origin
177
178
178
179
if is_py38 :
179
- from typing import TypedDict , _TypedDictMeta
180
+ from typing import TypedDict
180
181
else :
181
- _TypedDictMeta = None
182
182
TypedDict = ExtensionsTypedDict
183
183
184
184
def is_annotated (type ) -> bool :
@@ -274,20 +274,6 @@ def copy_with(type, args):
274
274
"""Replace a generic type's arguments."""
275
275
return type .copy_with (args )
276
276
277
- def is_typeddict (cls ) -> bool :
278
- return (
279
- cls .__class__ is _TypedDictMeta
280
- or (is_generic (cls ) and (cls .__origin__ .__class__ is _TypedDictMeta ))
281
- or (
282
- ExtensionsTypedDictMeta is not None
283
- and cls .__class__ is ExtensionsTypedDictMeta
284
- or (
285
- is_generic (cls )
286
- and (cls .__origin__ .__class__ is ExtensionsTypedDictMeta )
287
- )
288
- )
289
- )
290
-
291
277
def get_notrequired_base (type ) -> "Union[Any, Literal[NOTHING]]" :
292
278
if get_origin (type ) in (NotRequired , Required ):
293
279
return get_args (type )[0 ]
@@ -312,7 +298,6 @@ def get_notrequired_base(type) -> "Union[Any, Literal[NOTHING]]":
312
298
_AnnotatedAlias ,
313
299
_GenericAlias ,
314
300
_SpecialGenericAlias ,
315
- _TypedDictMeta ,
316
301
_UnionGenericAlias ,
317
302
)
318
303
@@ -389,20 +374,6 @@ def get_newtype_base(typ: Any) -> Optional[type]:
389
374
return supertype
390
375
return None
391
376
392
- def is_typeddict (cls ) -> bool :
393
- return (
394
- cls .__class__ is _TypedDictMeta
395
- or (is_generic (cls ) and (cls .__origin__ .__class__ is _TypedDictMeta ))
396
- or (
397
- ExtensionsTypedDictMeta is not None
398
- and cls .__class__ is ExtensionsTypedDictMeta
399
- or (
400
- is_generic (cls )
401
- and (cls .__origin__ .__class__ is ExtensionsTypedDictMeta )
402
- )
403
- )
404
- )
405
-
406
377
def get_notrequired_base (type ) -> "Union[Any, Literal[NOTHING]]" :
407
378
if get_origin (type ) in (NotRequired , Required ):
408
379
return get_args (type )[0 ]
0 commit comments