@@ -2250,17 +2250,18 @@ def _signature_from_callable(obj, *,
2250
2250
callable objects.
2251
2251
"""
2252
2252
2253
+ _get_signature_of = functools .partial (_signature_from_callable ,
2254
+ follow_wrapper_chains = follow_wrapper_chains ,
2255
+ skip_bound_arg = skip_bound_arg ,
2256
+ sigcls = sigcls )
2257
+
2253
2258
if not callable (obj ):
2254
2259
raise TypeError ('{!r} is not a callable object' .format (obj ))
2255
2260
2256
2261
if isinstance (obj , types .MethodType ):
2257
2262
# In this case we skip the first parameter of the underlying
2258
2263
# function (usually `self` or `cls`).
2259
- sig = _signature_from_callable (
2260
- obj .__func__ ,
2261
- follow_wrapper_chains = follow_wrapper_chains ,
2262
- skip_bound_arg = skip_bound_arg ,
2263
- sigcls = sigcls )
2264
+ sig = _get_signature_of (obj .__func__ )
2264
2265
2265
2266
if skip_bound_arg :
2266
2267
return _signature_bound_method (sig )
@@ -2274,11 +2275,7 @@ def _signature_from_callable(obj, *,
2274
2275
# If the unwrapped object is a *method*, we might want to
2275
2276
# skip its first parameter (self).
2276
2277
# See test_signature_wrapped_bound_method for details.
2277
- return _signature_from_callable (
2278
- obj ,
2279
- follow_wrapper_chains = follow_wrapper_chains ,
2280
- skip_bound_arg = skip_bound_arg ,
2281
- sigcls = sigcls )
2278
+ return _get_signature_of (obj )
2282
2279
2283
2280
try :
2284
2281
sig = obj .__signature__
@@ -2305,11 +2302,7 @@ def _signature_from_callable(obj, *,
2305
2302
# (usually `self`, or `cls`) will not be passed
2306
2303
# automatically (as for boundmethods)
2307
2304
2308
- wrapped_sig = _signature_from_callable (
2309
- partialmethod .func ,
2310
- follow_wrapper_chains = follow_wrapper_chains ,
2311
- skip_bound_arg = skip_bound_arg ,
2312
- sigcls = sigcls )
2305
+ wrapped_sig = _get_signature_of (partialmethod .func )
2313
2306
2314
2307
sig = _signature_get_partial (wrapped_sig , partialmethod , (None ,))
2315
2308
first_wrapped_param = tuple (wrapped_sig .parameters .values ())[0 ]
@@ -2335,11 +2328,7 @@ def _signature_from_callable(obj, *,
2335
2328
skip_bound_arg = skip_bound_arg )
2336
2329
2337
2330
if isinstance (obj , functools .partial ):
2338
- wrapped_sig = _signature_from_callable (
2339
- obj .func ,
2340
- follow_wrapper_chains = follow_wrapper_chains ,
2341
- skip_bound_arg = skip_bound_arg ,
2342
- sigcls = sigcls )
2331
+ wrapped_sig = _get_signature_of (obj .func )
2343
2332
return _signature_get_partial (wrapped_sig , obj )
2344
2333
2345
2334
sig = None
@@ -2350,29 +2339,17 @@ def _signature_from_callable(obj, *,
2350
2339
# in its metaclass
2351
2340
call = _signature_get_user_defined_method (type (obj ), '__call__' )
2352
2341
if call is not None :
2353
- sig = _signature_from_callable (
2354
- call ,
2355
- follow_wrapper_chains = follow_wrapper_chains ,
2356
- skip_bound_arg = skip_bound_arg ,
2357
- sigcls = sigcls )
2342
+ sig = _get_signature_of (call )
2358
2343
else :
2359
2344
# Now we check if the 'obj' class has a '__new__' method
2360
2345
new = _signature_get_user_defined_method (obj , '__new__' )
2361
2346
if new is not None :
2362
- sig = _signature_from_callable (
2363
- new ,
2364
- follow_wrapper_chains = follow_wrapper_chains ,
2365
- skip_bound_arg = skip_bound_arg ,
2366
- sigcls = sigcls )
2347
+ sig = _get_signature_of (new )
2367
2348
else :
2368
2349
# Finally, we should have at least __init__ implemented
2369
2350
init = _signature_get_user_defined_method (obj , '__init__' )
2370
2351
if init is not None :
2371
- sig = _signature_from_callable (
2372
- init ,
2373
- follow_wrapper_chains = follow_wrapper_chains ,
2374
- skip_bound_arg = skip_bound_arg ,
2375
- sigcls = sigcls )
2352
+ sig = _get_signature_of (init )
2376
2353
2377
2354
if sig is None :
2378
2355
# At this point we know, that `obj` is a class, with no user-
@@ -2418,11 +2395,7 @@ def _signature_from_callable(obj, *,
2418
2395
call = _signature_get_user_defined_method (type (obj ), '__call__' )
2419
2396
if call is not None :
2420
2397
try :
2421
- sig = _signature_from_callable (
2422
- call ,
2423
- follow_wrapper_chains = follow_wrapper_chains ,
2424
- skip_bound_arg = skip_bound_arg ,
2425
- sigcls = sigcls )
2398
+ sig = _get_signature_of (call )
2426
2399
except ValueError as ex :
2427
2400
msg = 'no signature found for {!r}' .format (obj )
2428
2401
raise ValueError (msg ) from ex
0 commit comments