@@ -148,17 +148,25 @@ def meth_self_o(self, object, /): pass
148148def meth_type_noargs (type , / ): pass
149149def meth_type_o (type , object , / ): pass
150150
151- # Simple decorator for test cases that using decorated functions
152- def identity (func ):
151+ # Decorator decorator that returns a simple wrapped function
152+ def identity_wrapper (func ):
153153 @functools .wraps (func )
154154 def wrapped (* args , ** kwargs ):
155155 return func (* args , ** kwargs )
156156 return wrapped
157157
158- # Simple descriptor that decorates a function
159- class DescWithDeco :
158+ # Original signature of the simple wrapped function returned by
159+ # identity_wrapper().
160+ varargs_signature = (
161+ (('args' , ..., ..., 'var_positional' ),
162+ ('kwargs' , ..., ..., 'var_keyword' )),
163+ ...,
164+ )
165+
166+ # Decorator decorator that returns a simple descriptor
167+ class custom_descriptor :
160168 def __init__ (self , func ):
161- self .func = identity ( func )
169+ self .func = func
162170
163171 def __get__ (self , instance , owner ):
164172 return self .func .__get__ (instance , owner )
@@ -4044,7 +4052,7 @@ def __init__(self, b):
40444052
40454053 def test_signature_on_class_with_wrapped_metaclass_call (self ):
40464054 class CM (type ):
4047- @identity
4055+ @identity_wrapper
40484056 def __call__ (cls , a ):
40494057 pass
40504058 class C (metaclass = CM ):
@@ -4058,7 +4066,7 @@ def __init__(self, b):
40584066 with self .subTest ('classmethod' ):
40594067 class CM (type ):
40604068 @classmethod
4061- @identity
4069+ @identity_wrapper
40624070 def __call__ (cls , a ):
40634071 return a
40644072 class C (metaclass = CM ):
@@ -4073,7 +4081,7 @@ def __init__(self, b):
40734081 with self .subTest ('staticmethod' ):
40744082 class CM (type ):
40754083 @staticmethod
4076- @identity
4084+ @identity_wrapper
40774085 def __call__ (a ):
40784086 return a
40794087 class C (metaclass = CM ):
@@ -4087,7 +4095,7 @@ def __init__(self, b):
40874095
40884096 with self .subTest ('MethodType' ):
40894097 class A :
4090- @identity
4098+ @identity_wrapper
40914099 def call (self , a ):
40924100 return a
40934101 class CM (type ):
@@ -4103,7 +4111,8 @@ def __init__(self, b):
41034111
41044112 with self .subTest ('descriptor' ):
41054113 class CM (type ):
4106- @DescWithDeco
4114+ @custom_descriptor
4115+ @identity_wrapper
41074116 def __call__ (self , a ):
41084117 return a
41094118 class C (metaclass = CM ):
@@ -4114,10 +4123,18 @@ def __init__(self, b):
41144123 self .assertEqual (self .signature (C ),
41154124 ((('a' , ..., ..., "positional_or_keyword" ),),
41164125 ...))
4126+ self .assertEqual (self .signature (C .__call__ ),
4127+ ((('a' , ..., ..., "positional_or_keyword" ),),
4128+ ...))
4129+
4130+ self .assertEqual (self .signature (C , follow_wrapped = False ),
4131+ varargs_signature )
4132+ self .assertEqual (self .signature (C .__call__ , follow_wrapped = False ),
4133+ varargs_signature )
41174134
4118- def test_signature_on_class_with_decorated_init (self ):
4135+ def test_signature_on_class_with_wrapped_init (self ):
41194136 class C :
4120- @identity
4137+ @identity_wrapper
41214138 def __init__ (self , b ):
41224139 pass
41234140
@@ -4129,7 +4146,7 @@ def __init__(self, b):
41294146 with self .subTest ('classmethod' ):
41304147 class C :
41314148 @classmethod
4132- @identity
4149+ @identity_wrapper
41334150 def __init__ (cls , b ):
41344151 pass
41354152
@@ -4141,7 +4158,7 @@ def __init__(cls, b):
41414158 with self .subTest ('staticmethod' ):
41424159 class C :
41434160 @staticmethod
4144- @identity
4161+ @identity_wrapper
41454162 def __init__ (b ):
41464163 pass
41474164
@@ -4152,7 +4169,7 @@ def __init__(b):
41524169
41534170 with self .subTest ('MethodType' ):
41544171 class A :
4155- @identity
4172+ @identity_wrapper
41564173 def call (self , a ):
41574174 pass
41584175
@@ -4166,7 +4183,7 @@ class C:
41664183
41674184 with self .subTest ('partial' ):
41684185 class C :
4169- __init__ = functools .partial (identity (lambda x , a , b : None ), 2 )
4186+ __init__ = functools .partial (identity_wrapper (lambda x , a , b : None ), 2 )
41704187
41714188 C (1 ) # does not raise
41724189 self .assertEqual (self .signature (C ),
@@ -4175,7 +4192,7 @@ class C:
41754192
41764193 with self .subTest ('partialmethod' ):
41774194 class C :
4178- @identity
4195+ @identity_wrapper
41794196 def _init (self , x , a ):
41804197 self .a = (x , a )
41814198 __init__ = functools .partialmethod (_init , 2 )
@@ -4187,35 +4204,29 @@ def _init(self, x, a):
41874204
41884205 with self .subTest ('descriptor' ):
41894206 class C :
4190- @DescWithDeco
4207+ @custom_descriptor
4208+ @identity_wrapper
41914209 def __init__ (self , a ):
41924210 pass
41934211
41944212 C (1 ) # does not raise
41954213 self .assertEqual (self .signature (C ),
41964214 ((('a' , ..., ..., "positional_or_keyword" ),),
41974215 ...))
4198-
41994216 self .assertEqual (self .signature (C .__init__ ),
42004217 ((('self' , ..., ..., "positional_or_keyword" ),
42014218 ('a' , ..., ..., "positional_or_keyword" )),
42024219 ...))
42034220
4204- varargs_signature = (
4205- (('args' , ..., ..., 'var_positional' ),
4206- ('kwargs' , ..., ..., 'var_keyword' )),
4207- ...,
4208- )
42094221 self .assertEqual (self .signature (C , follow_wrapped = False ),
42104222 varargs_signature )
42114223 self .assertEqual (self .signature (C .__new__ , follow_wrapped = False ),
42124224 varargs_signature )
42134225
4214-
4215- def test_signature_on_class_with_decorated_new (self ):
4226+ def test_signature_on_class_with_wrapped_new (self ):
42164227 with self .subTest ('FunctionType' ):
42174228 class C :
4218- @identity
4229+ @identity_wrapper
42194230 def __new__ (cls , a ):
42204231 return a
42214232
@@ -4227,7 +4238,7 @@ def __new__(cls, a):
42274238 with self .subTest ('classmethod' ):
42284239 class C :
42294240 @classmethod
4230- @identity
4241+ @identity_wrapper
42314242 def __new__ (cls , cls2 , a ):
42324243 return a
42334244
@@ -4239,7 +4250,7 @@ def __new__(cls, cls2, a):
42394250 with self .subTest ('staticmethod' ):
42404251 class C :
42414252 @staticmethod
4242- @identity
4253+ @identity_wrapper
42434254 def __new__ (cls , a ):
42444255 return a
42454256
@@ -4250,7 +4261,7 @@ def __new__(cls, a):
42504261
42514262 with self .subTest ('MethodType' ):
42524263 class A :
4253- @identity
4264+ @identity_wrapper
42544265 def call (self , cls , a ):
42554266 return a
42564267 class C :
@@ -4263,7 +4274,7 @@ class C:
42634274
42644275 with self .subTest ('partial' ):
42654276 class C :
4266- __new__ = functools .partial (identity (lambda x , cls , a : (x , a )), 2 )
4277+ __new__ = functools .partial (identity_wrapper (lambda x , cls , a : (x , a )), 2 )
42674278
42684279 self .assertEqual (C (1 ), (2 , 1 ))
42694280 self .assertEqual (self .signature (C ),
@@ -4272,7 +4283,7 @@ class C:
42724283
42734284 with self .subTest ('partialmethod' ):
42744285 class C :
4275- __new__ = functools .partialmethod (identity (lambda cls , x , a : (x , a )), 2 )
4286+ __new__ = functools .partialmethod (identity_wrapper (lambda cls , x , a : (x , a )), 2 )
42764287
42774288 self .assertEqual (C (1 ), (2 , 1 ))
42784289 self .assertEqual (self .signature (C ),
@@ -4281,25 +4292,20 @@ class C:
42814292
42824293 with self .subTest ('descriptor' ):
42834294 class C :
4284- @DescWithDeco
4295+ @custom_descriptor
4296+ @identity_wrapper
42854297 def __new__ (cls , a ):
42864298 return a
42874299
42884300 self .assertEqual (C (1 ), 1 )
42894301 self .assertEqual (self .signature (C ),
42904302 ((('a' , ..., ..., "positional_or_keyword" ),),
42914303 ...))
4292-
42934304 self .assertEqual (self .signature (C .__new__ ),
42944305 ((('cls' , ..., ..., "positional_or_keyword" ),
42954306 ('a' , ..., ..., "positional_or_keyword" )),
42964307 ...))
42974308
4298- varargs_signature = (
4299- (('args' , ..., ..., 'var_positional' ),
4300- ('kwargs' , ..., ..., 'var_keyword' )),
4301- ...,
4302- )
43034309 self .assertEqual (self .signature (C , follow_wrapped = False ),
43044310 varargs_signature )
43054311 self .assertEqual (self .signature (C .__new__ , follow_wrapped = False ),
0 commit comments