MCPcopy Index your code
hub / github.com/python/cpython / getmethparlist

Function getmethparlist

Lib/turtle.py:4030–4064  ·  view source on GitHub ↗

Get strings describing the arguments for the given object Returns a pair of strings representing function parameter lists including parenthesis. The first string is suitable for use in function definition and the second is suitable for use in function call. The "self" parameter is

(ob)

Source from the content-addressed store, hash-verified

4028
4029
4030def getmethparlist(ob):
4031 """Get strings describing the arguments for the given object
4032
4033 Returns a pair of strings representing function parameter lists
4034 including parenthesis. The first string is suitable for use in
4035 function definition and the second is suitable for use in function
4036 call. The "self" parameter is not included.
4037 """
4038 orig_sig = inspect.signature(ob)
4039 # bit of a hack for methods - turn it into a function
4040 # but we drop the "self" param.
4041 # Try and build one for Python defined functions
4042 func_sig = orig_sig.replace(
4043 parameters=list(orig_sig.parameters.values())[1:],
4044 )
4045
4046 call_args = []
4047 for param in func_sig.parameters.values():
4048 match param.kind:
4049 case (
4050 inspect.Parameter.POSITIONAL_ONLY
4051 | inspect.Parameter.POSITIONAL_OR_KEYWORD
4052 ):
4053 call_args.append(param.name)
4054 case inspect.Parameter.VAR_POSITIONAL:
4055 call_args.append(f'*{param.name}')
4056 case inspect.Parameter.KEYWORD_ONLY:
4057 call_args.append(f'{param.name}={param.name}')
4058 case inspect.Parameter.VAR_KEYWORD:
4059 call_args.append(f'**{param.name}')
4060 case _:
4061 raise RuntimeError('Unsupported parameter kind', param.kind)
4062 call_text = f'({', '.join(call_args)})'
4063
4064 return str(func_sig), call_text
4065
4066def _turtle_docrevise(docstr):
4067 """To reduce docstrings from RawTurtle class for functions

Callers 1

_make_global_funcsFunction · 0.85

Calls 7

listClass · 0.85
strFunction · 0.85
signatureMethod · 0.45
replaceMethod · 0.45
valuesMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…