mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
create function alias to improve api documentation
This commit is contained in:
parent
64d5c2362a
commit
6a8b61bd12
1 changed files with 27 additions and 1 deletions
|
@ -2001,7 +2001,7 @@ def get_hash(path, form='md5', chunk_size=65536):
|
|||
|
||||
def namespaced_function(function, global_dict, defaults=None):
|
||||
'''
|
||||
Redefine(clone) a function under a different globals() namespace scope
|
||||
Redefine (clone) a function under a different globals() namespace scope
|
||||
'''
|
||||
if defaults is None:
|
||||
defaults = function.__defaults__
|
||||
|
@ -2016,6 +2016,32 @@ def namespaced_function(function, global_dict, defaults=None):
|
|||
return new_namespaced_function
|
||||
|
||||
|
||||
def alias_function(fun, name, doc=None):
|
||||
'''
|
||||
Copy a function
|
||||
'''
|
||||
alias_fun = types.FunctionType(fun.__code__,
|
||||
fun.__globals__,
|
||||
name,
|
||||
fun.__defaults__,
|
||||
fun.__closure__)
|
||||
alias_fun.__dict__.update(fun.__dict__)
|
||||
|
||||
if doc and isinstance(doc, six.string_types):
|
||||
alias_fun.__doc__ = doc
|
||||
else:
|
||||
if six.PY3:
|
||||
orig_name = fun.__name__
|
||||
else:
|
||||
orig_name = fun.func_name # pylint: disable=incompatible-py3-code
|
||||
|
||||
alias_msg = ('\nThis function is an alias of '
|
||||
'``{0}``.\n'.format(orig_name))
|
||||
alias_fun.__doc__ = alias_msg + fun.__doc__
|
||||
|
||||
return alias_fun
|
||||
|
||||
|
||||
def _win_console_event_handler(event):
|
||||
if event == 5:
|
||||
# Do nothing on CTRL_LOGOFF_EVENT
|
||||
|
|
Loading…
Add table
Reference in a new issue