MCPcopy Index your code
hub / github.com/RustPython/RustPython / _signature_strip_non_python_syntax

Function _signature_strip_non_python_syntax

Lib/inspect.py:2094–2141  ·  view source on GitHub ↗

Private helper function. Takes a signature in Argument Clinic's extended signature format. Returns a tuple of two things: * that signature re-rendered in standard Python syntax, and * the index of the "self" parameter (generally 0), or None if the function does not

(signature)

Source from the content-addressed store, hash-verified

2092
2093
2094def _signature_strip_non_python_syntax(signature):
2095 """
2096 Private helper function. Takes a signature in Argument Clinic's
2097 extended signature format.
2098
2099 Returns a tuple of two things:
2100 * that signature re-rendered in standard Python syntax, and
2101 * the index of the "self" parameter (generally 0), or None if
2102 the function does not have a "self" parameter.
2103 """
2104
2105 if not signature:
2106 return signature, None
2107
2108 self_parameter = None
2109
2110 lines = [l.encode('ascii') for l in signature.split('\n') if l]
2111 generator = iter(lines).__next__
2112 token_stream = tokenize.tokenize(generator)
2113
2114 text = []
2115 add = text.append
2116
2117 current_parameter = 0
2118 OP = token.OP
2119 ERRORTOKEN = token.ERRORTOKEN
2120
2121 # token stream always starts with ENCODING token, skip it
2122 t = next(token_stream)
2123 assert t.type == tokenize.ENCODING
2124
2125 for t in token_stream:
2126 type, string = t.type, t.string
2127
2128 if type == OP:
2129 if string == ',':
2130 current_parameter += 1
2131
2132 if (type == OP) and (string == '$'):
2133 assert self_parameter is None
2134 self_parameter = current_parameter
2135 continue
2136
2137 add(string)
2138 if (string == ','):
2139 add(' ')
2140 clean_signature = ''.join(text).strip().replace("\n", "")
2141 return clean_signature, self_parameter
2142
2143
2144def _signature_fromstr(cls, obj, s, skip_bound_arg=True):

Callers 1

_signature_fromstrFunction · 0.85

Calls 8

iterFunction · 0.85
nextFunction · 0.85
addFunction · 0.70
encodeMethod · 0.45
splitMethod · 0.45
replaceMethod · 0.45
stripMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected