@@ -953,21 +953,6 @@ def __round__(self, ndigits: int = 0) -> T_co:
953
953
pass
954
954
955
955
956
- def _ensure_subclassable (mro_entries ):
957
- def inner (func ):
958
- if sys .implementation .name == "pypy" and sys .version_info < (3 , 9 ):
959
- cls_dict = {
960
- "__call__" : staticmethod (func ),
961
- "__mro_entries__" : staticmethod (mro_entries )
962
- }
963
- t = type (func .__name__ , (), cls_dict )
964
- return functools .update_wrapper (t (), func )
965
- else :
966
- func .__mro_entries__ = mro_entries
967
- return func
968
- return inner
969
-
970
-
971
956
if sys .version_info >= (3 , 13 ):
972
957
# The standard library TypedDict in Python 3.8 does not store runtime information
973
958
# about which (if any) keys are optional. See https://bugs.python.org/issue38834
@@ -1074,9 +1059,6 @@ def __subclasscheck__(cls, other):
1074
1059
1075
1060
__instancecheck__ = __subclasscheck__
1076
1061
1077
- _TypedDict = type .__new__ (_TypedDictMeta , 'TypedDict' , (), {})
1078
-
1079
- @_ensure_subclassable (lambda bases : (_TypedDict ,))
1080
1062
def TypedDict (__typename , __fields = _marker , * , total = True , ** kwargs ):
1081
1063
"""A simple typed namespace. At runtime it is equivalent to a plain dict.
1082
1064
@@ -1160,6 +1142,9 @@ class Point2D(TypedDict):
1160
1142
td .__orig_bases__ = (TypedDict ,)
1161
1143
return td
1162
1144
1145
+ _TypedDict = type .__new__ (_TypedDictMeta , 'TypedDict' , (), {})
1146
+ TypedDict .__mro_entries__ = lambda bases : (_TypedDict ,)
1147
+
1163
1148
if hasattr (typing , "_TypedDictMeta" ):
1164
1149
_TYPEDDICT_TYPES = (typing ._TypedDictMeta , _TypedDictMeta )
1165
1150
else :
@@ -2648,13 +2633,6 @@ def __new__(cls, typename, bases, ns):
2648
2633
nm_tpl .__init_subclass__ ()
2649
2634
return nm_tpl
2650
2635
2651
- _NamedTuple = type .__new__ (_NamedTupleMeta , 'NamedTuple' , (), {})
2652
-
2653
- def _namedtuple_mro_entries (bases ):
2654
- assert NamedTuple in bases
2655
- return (_NamedTuple ,)
2656
-
2657
- @_ensure_subclassable (_namedtuple_mro_entries )
2658
2636
def NamedTuple (__typename , __fields = _marker , ** kwargs ):
2659
2637
"""Typed version of namedtuple.
2660
2638
@@ -2720,15 +2698,19 @@ class Employee(NamedTuple):
2720
2698
nt .__orig_bases__ = (NamedTuple ,)
2721
2699
return nt
2722
2700
2701
+ _NamedTuple = type .__new__ (_NamedTupleMeta , 'NamedTuple' , (), {})
2702
+
2723
2703
# On 3.8+, alter the signature so that it matches typing.NamedTuple.
2724
2704
# The signature of typing.NamedTuple on >=3.8 is invalid syntax in Python 3.7,
2725
2705
# so just leave the signature as it is on 3.7.
2726
2706
if sys .version_info >= (3 , 8 ):
2727
- _new_signature = '(typename, fields=None, /, **kwargs)'
2728
- if isinstance (NamedTuple , _types .FunctionType ):
2729
- NamedTuple .__text_signature__ = _new_signature
2730
- else :
2731
- NamedTuple .__call__ .__text_signature__ = _new_signature
2707
+ NamedTuple .__text_signature__ = '(typename, fields=None, /, **kwargs)'
2708
+
2709
+ def _namedtuple_mro_entries (bases ):
2710
+ assert NamedTuple in bases
2711
+ return (_NamedTuple ,)
2712
+
2713
+ NamedTuple .__mro_entries__ = _namedtuple_mro_entries
2732
2714
2733
2715
2734
2716
if hasattr (collections .abc , "Buffer" ):
@@ -3004,8 +2986,7 @@ def is_protocol(__tp: type) -> bool:
3004
2986
return (
3005
2987
isinstance (__tp , type )
3006
2988
and getattr (__tp , '_is_protocol' , False )
3007
- and __tp is not Protocol
3008
- and __tp is not getattr (typing , "Protocol" , object ())
2989
+ and __tp != Protocol
3009
2990
)
3010
2991
3011
2992
def get_protocol_members (__tp : type ) -> typing .FrozenSet [str ]:
0 commit comments