@@ -1223,7 +1223,50 @@ def _create_typeddict(
12231223 td .__orig_bases__ = (TypedDict ,)
12241224 return td
12251225
1226- class _TypedDictSpecialForm (_ExtensionsSpecialForm , _root = True ):
1226+ # Cannot inherit from typing._SpecialForm, because then typing._type_check
1227+ # would reject TypedDict as a type, and we need that to work for compatibility.
1228+ if hasattr (typing , "_NotIterable" ):
1229+ _special_form_bases = (typing ._Final , typing ._NotIterable )
1230+ else :
1231+ _special_form_bases = (typing ._Final ,)
1232+
1233+ class _TypedDictSpecialForm (* _special_form_bases , _root = True ):
1234+ __slots__ = ('_name' , '__doc__' , '_getitem' )
1235+
1236+ def __init__ (self , getitem ):
1237+ self ._getitem = getitem
1238+ self ._name = getitem .__name__
1239+ self .__doc__ = getitem .__doc__
1240+
1241+ def __getattr__ (self , item ):
1242+ if item in {'__name__' , '__qualname__' }:
1243+ return self ._name
1244+
1245+ raise AttributeError (item )
1246+
1247+ def __repr__ (self ):
1248+ return 'typing_extensions.' + self ._name
1249+
1250+ def __reduce__ (self ):
1251+ return self ._name
1252+
1253+ if sys .version_info >= (3 , 10 ):
1254+ def __or__ (self , other ):
1255+ return typing .Union [self , other ]
1256+
1257+ def __ror__ (self , other ):
1258+ return typing .Union [other , self ]
1259+
1260+ def __instancecheck__ (self , obj ):
1261+ raise TypeError (f"{ self } cannot be used with isinstance()" )
1262+
1263+ def __subclasscheck__ (self , cls ):
1264+ raise TypeError (f"{ self } cannot be used with issubclass()" )
1265+
1266+ @typing ._tp_cache
1267+ def __getitem__ (self , parameters ):
1268+ return self ._getitem (self , parameters )
1269+
12271270 def __call__ (
12281271 self ,
12291272 typename ,
0 commit comments