@@ -2106,26 +2106,21 @@ def _signature_strip_non_python_syntax(signature):
21062106 Private helper function. Takes a signature in Argument Clinic's
21072107 extended signature format.
21082108
2109- Returns a tuple of three things:
2110- * that signature re-rendered in standard Python syntax,
2109+ Returns a tuple of two things:
2110+ * that signature re-rendered in standard Python syntax, and
21112111 * the index of the "self" parameter (generally 0), or None if
2112- the function does not have a "self" parameter, and
2113- * the index of the last "positional only" parameter,
2114- or None if the signature has no positional-only parameters.
2112+ the function does not have a "self" parameter.
21152113 """
21162114
21172115 if not signature :
2118- return signature , None , None
2116+ return signature , None
21192117
21202118 self_parameter = None
2121- last_positional_only = None
21222119
21232120 lines = [l .encode ('ascii' ) for l in signature .split ('\n ' ) if l ]
21242121 generator = iter (lines ).__next__
21252122 token_stream = tokenize .tokenize (generator )
21262123
2127- delayed_comma = False
2128- skip_next_comma = False
21292124 text = []
21302125 add = text .append
21312126
@@ -2142,35 +2137,18 @@ def _signature_strip_non_python_syntax(signature):
21422137
21432138 if type == OP :
21442139 if string == ',' :
2145- if skip_next_comma :
2146- skip_next_comma = False
2147- else :
2148- assert not delayed_comma
2149- delayed_comma = True
2150- current_parameter += 1
2151- continue
2152-
2153- if string == '/' :
2154- assert not skip_next_comma
2155- assert last_positional_only is None
2156- skip_next_comma = True
2157- last_positional_only = current_parameter - 1
2158- continue
2140+ current_parameter += 1
21592141
21602142 if (type == ERRORTOKEN ) and (string == '$' ):
21612143 assert self_parameter is None
21622144 self_parameter = current_parameter
21632145 continue
21642146
2165- if delayed_comma :
2166- delayed_comma = False
2167- if not ((type == OP ) and (string == ')' )):
2168- add (', ' )
21692147 add (string )
21702148 if (string == ',' ):
21712149 add (' ' )
21722150 clean_signature = '' .join (text )
2173- return clean_signature , self_parameter , last_positional_only
2151+ return clean_signature , self_parameter
21742152
21752153
21762154def _signature_fromstr (cls , obj , s , skip_bound_arg = True ):
@@ -2179,8 +2157,7 @@ def _signature_fromstr(cls, obj, s, skip_bound_arg=True):
21792157 """
21802158 Parameter = cls ._parameter_cls
21812159
2182- clean_signature , self_parameter , last_positional_only = \
2183- _signature_strip_non_python_syntax (s )
2160+ clean_signature , self_parameter = _signature_strip_non_python_syntax (s )
21842161
21852162 program = "def foo" + clean_signature + ": pass"
21862163
@@ -2269,17 +2246,17 @@ def p(name_node, default_node, default=empty):
22692246 parameters .append (Parameter (name , kind , default = default , annotation = empty ))
22702247
22712248 # non-keyword-only parameters
2272- args = reversed (f .args .args )
2273- defaults = reversed (f .args .defaults )
2274- iter = itertools .zip_longest (args , defaults , fillvalue = None )
2275- if last_positional_only is not None :
2276- kind = Parameter .POSITIONAL_ONLY
2277- else :
2278- kind = Parameter .POSITIONAL_OR_KEYWORD
2279- for i , (name , default ) in enumerate (reversed (list (iter ))):
2249+ total_non_kw_args = len (f .args .posonlyargs ) + len (f .args .args )
2250+ required_non_kw_args = total_non_kw_args - len (f .args .defaults )
2251+ defaults = itertools .chain (itertools .repeat (None , required_non_kw_args ), f .args .defaults )
2252+
2253+ kind = Parameter .POSITIONAL_ONLY
2254+ for (name , default ) in zip (f .args .posonlyargs , defaults ):
2255+ p (name , default )
2256+
2257+ kind = Parameter .POSITIONAL_OR_KEYWORD
2258+ for (name , default ) in zip (f .args .args , defaults ):
22802259 p (name , default )
2281- if i == last_positional_only :
2282- kind = Parameter .POSITIONAL_OR_KEYWORD
22832260
22842261 # *args
22852262 if f .args .vararg :
0 commit comments