@@ -96,14 +96,7 @@ def _cli_patch(cli_args): # pragma: no coverage
96
96
import configparser
97
97
from datetime import timezone
98
98
UTC = timezone .utc
99
- # getfullargspec was deprecated in 3.5 and un-deprecated in 3.6
100
- # getargspec was deprecated in 3.0 and removed in 3.11
101
- from inspect import getfullargspec
102
-
103
- def getargspec (func ):
104
- spec = getfullargspec (func )
105
- kwargs = makelist (spec [0 ]) + makelist (spec .kwonlyargs )
106
- return kwargs , spec [1 ], spec [2 ], spec [3 ]
99
+ import inspect
107
100
108
101
json_loads = lambda s : json_lds (touni (s ))
109
102
callable = lambda x : hasattr (x , '__call__' )
@@ -553,7 +546,10 @@ def get_callback_args(self):
553
546
""" Return a list of argument names the callback (most likely) accepts
554
547
as keyword arguments. If the callback is a decorated function, try
555
548
to recover the original function before inspection. """
556
- return getargspec (self .get_undecorated_callback ())[0 ]
549
+ sig = inspect .signature (self .get_undecorated_callback ())
550
+ return [p .name for p in sig .parameters .values () if p .kind in (
551
+ p .POSITIONAL_OR_KEYWORD , p .KEYWORD_ONLY
552
+ )]
557
553
558
554
def get_config (self , key , default = None ):
559
555
""" Lookup a config field and return its value, first checking the
@@ -3006,13 +3002,15 @@ def yieldroutes(func):
3006
3002
d(x=5, y=6) -> '/d' and '/d/<x>' and '/d/<x>/<y>'
3007
3003
"""
3008
3004
path = '/' + func .__name__ .replace ('__' , '/' ).lstrip ('/' )
3009
- spec = getargspec (func )
3010
- argc = len (spec [0 ]) - len (spec [3 ] or [])
3011
- path += ('/<%s>' * argc ) % tuple (spec [0 ][:argc ])
3005
+ sig = inspect .signature (func , follow_wrapped = False )
3006
+ for p in sig .parameters .values ():
3007
+ if p .kind == p .POSITIONAL_ONLY :
3008
+ raise ValueError ("Invalid signature for yieldroutes: %s" % sig )
3009
+ if p .kind in (p .POSITIONAL_OR_KEYWORD , p .KEYWORD_ONLY ):
3010
+ if p .default != p .empty :
3011
+ yield path # Yield path without this (optional) parameter.
3012
+ path += "/<%s>" % p .name
3012
3013
yield path
3013
- for arg in spec [0 ][argc :]:
3014
- path += '/<%s>' % arg
3015
- yield path
3016
3014
3017
3015
3018
3016
def path_shift (script_name , path_info , shift = 1 ):
0 commit comments