@@ -148,6 +148,21 @@ 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 ):
153+ @functools .wraps (func )
154+ def wrapped (* args , ** kwargs ):
155+ return func (* args , ** kwargs )
156+ return wrapped
157+
158+ # Simple descriptor that decorates a function
159+ class DescWithDeco :
160+ def __init__ (self , func ):
161+ self .func = identity (func )
162+
163+ def __get__ (self , instance , owner ):
164+ return self .func .__get__ (instance , owner )
165+
151166
152167class TestPredicates (IsTestBase ):
153168
@@ -4028,12 +4043,6 @@ def __init__(self, b):
40284043 ...))
40294044
40304045 def test_signature_on_class_with_decorated_init (self ):
4031- def identity (func ):
4032- @functools .wraps (func )
4033- def wrapped (* args , ** kwargs ):
4034- return func (* args , ** kwargs )
4035- return wrapped
4036-
40374046 class C :
40384047 @identity
40394048 def __init__ (self , b ):
@@ -4084,7 +4093,7 @@ class C:
40844093
40854094 with self .subTest ('partial' ):
40864095 class C :
4087- __init__ = identity ( functools .partial (lambda x , a , b : None , 2 ) )
4096+ __init__ = functools .partial (identity ( lambda x , a , b : None ) , 2 )
40884097
40894098 C (1 ) # does not raise
40904099 self .assertEqual (self .signature (C ),
@@ -4103,16 +4112,9 @@ def _init(self, x, a):
41034112 ((('a' , ..., ..., "positional_or_keyword" ),),
41044113 ...))
41054114
4106- class Desc :
4107- def __init__ (self , func ):
4108- self .func = identity (func )
4109-
4110- def __get__ (self , instance , owner ):
4111- return self .func .__get__ (instance , owner )
4112-
41134115 with self .subTest ('descriptor' ):
41144116 class C :
4115- __init__ = Desc (lambda self , a : None )
4117+ __init__ = DescWithDeco (lambda self , a : None )
41164118
41174119 C (1 ) # does not raise
41184120 self .assertEqual (self .signature (C ),
@@ -4192,7 +4194,7 @@ class C:
41924194
41934195 with self .subTest ('partial' ):
41944196 class C :
4195- __new__ = identity ( functools .partial (lambda x , cls , a : (x , a ), 2 ) )
4197+ __new__ = functools .partial (identity ( lambda x , cls , a : (x , a )) , 2 )
41964198
41974199 self .assertEqual (C (1 ), (2 , 1 ))
41984200 self .assertEqual (self .signature (C ),
@@ -4208,16 +4210,9 @@ class C:
42084210 ((('a' , ..., ..., "positional_or_keyword" ),),
42094211 ...))
42104212
4211- class Desc :
4212- def __init__ (self , func ):
4213- self .func = identity (func )
4214-
4215- def __get__ (self , instance , owner ):
4216- return self .func .__get__ (instance , owner )
4217-
42184213 with self .subTest ('descriptor' ):
42194214 class C :
4220- __new__ = Desc (lambda cls , a : a )
4215+ __new__ = DescWithDeco (lambda cls , a : a )
42214216
42224217 self .assertEqual (C (1 ), 1 )
42234218 self .assertEqual (self .signature (C ),
0 commit comments