cornflakes.common.get_method_definition
- cornflakes.common.get_method_definition(func)
This function returns the string representation of a given function. It supports both lambda functions and functions defined using def. It also supports functools.partial objects.
- Parameter:
func (callable) – A function or a functools.partial object.
- Rückgabe:
A string representation of the function or functools.partial object.
- Rückgabetyp:
str
Examples: >>> def original_function(x, y, z=3): … return x + y + z … >>> p = partial(original_function, 1, z=5) >>> get_method_definition(p) # doctest: +NORMALIZE_WHITESPACE ‚partial(original_function, 1, z=5)‘
# >>> l = lambda x, y, z: print(x, y, z) # >>> get_method_definition(l) # ‚lambda x, y, z: print(x, y, z)‘ # # >>> method = partial(lambda x, y, z: print(x, y, z), x=1) # >>> get_method_definition(method) # ‚partial(lambda x, y, z: print(x, y, z), x=1)‘