@@ -2106,19 +2106,16 @@ def _signature_strip_non_python_syntax(signature):
2106
2106
Private helper function. Takes a signature in Argument Clinic's
2107
2107
extended signature format.
2108
2108
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
2111
2111
* 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.
2115
2113
"""
2116
2114
2117
2115
if not signature :
2118
- return signature , None , None
2116
+ return signature , None
2119
2117
2120
2118
self_parameter = None
2121
- last_positional_only = None
2122
2119
2123
2120
lines = [l .encode ('ascii' ) for l in signature .split ('\n ' ) if l ]
2124
2121
generator = iter (lines ).__next__
@@ -2150,13 +2147,6 @@ def _signature_strip_non_python_syntax(signature):
2150
2147
current_parameter += 1
2151
2148
continue
2152
2149
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
2159
-
2160
2150
if (type == ERRORTOKEN ) and (string == '$' ):
2161
2151
assert self_parameter is None
2162
2152
self_parameter = current_parameter
@@ -2170,7 +2160,7 @@ def _signature_strip_non_python_syntax(signature):
2170
2160
if (string == ',' ):
2171
2161
add (' ' )
2172
2162
clean_signature = '' .join (text )
2173
- return clean_signature , self_parameter , last_positional_only
2163
+ return clean_signature , self_parameter
2174
2164
2175
2165
2176
2166
def _signature_fromstr (cls , obj , s , skip_bound_arg = True ):
@@ -2179,8 +2169,7 @@ def _signature_fromstr(cls, obj, s, skip_bound_arg=True):
2179
2169
"""
2180
2170
Parameter = cls ._parameter_cls
2181
2171
2182
- clean_signature , self_parameter , last_positional_only = \
2183
- _signature_strip_non_python_syntax (s )
2172
+ clean_signature , self_parameter = _signature_strip_non_python_syntax (s )
2184
2173
2185
2174
program = "def foo" + clean_signature + ": pass"
2186
2175
@@ -2269,17 +2258,17 @@ def p(name_node, default_node, default=empty):
2269
2258
parameters .append (Parameter (name , kind , default = default , annotation = empty ))
2270
2259
2271
2260
# 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 ))):
2261
+ total_non_kw_args = len (f .args .posonlyargs ) + len (f .args .args )
2262
+ required_non_kw_args = total_non_kw_args - len (f .args .defaults )
2263
+ defaults = itertools .chain (itertools .repeat (None , required_non_kw_args ), f .args .defaults )
2264
+
2265
+ kind = Parameter .POSITIONAL_ONLY
2266
+ for (name , default ) in zip (f .args .posonlyargs , defaults ):
2267
+ p (name , default )
2268
+
2269
+ kind = Parameter .POSITIONAL_OR_KEYWORD
2270
+ for (name , default ) in zip (f .args .args , defaults ):
2280
2271
p (name , default )
2281
- if i == last_positional_only :
2282
- kind = Parameter .POSITIONAL_OR_KEYWORD
2283
2272
2284
2273
# *args
2285
2274
if f .args .vararg :
0 commit comments