MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / decorate

Function decorate

lib/sqlalchemy/testing/plugin/pytestplugin.py:648–676  ·  view source on GitHub ↗
(fn, add_positional_parameters=())

Source from the content-addressed store, hash-verified

646 return env[fn_name]
647
648 def decorate(fn, add_positional_parameters=()):
649 spec = inspect_getfullargspec(fn)
650 if add_positional_parameters:
651 spec.args.extend(add_positional_parameters)
652
653 metadata = dict(
654 __target_fn="__target_fn", __orig_fn="__orig_fn", name=fn.__name__
655 )
656 metadata.update(format_argspec_plus(spec, grouped=False))
657 code = """\
658def %(name)s%(grouped_args)s:
659 return %(__target_fn)s(%(__orig_fn)s, %(apply_kw)s)
660""" % metadata
661 decorated = _exec_code_in_env(
662 code, {"__target_fn": target, "__orig_fn": fn}, fn.__name__
663 )
664 if not add_positional_parameters:
665 decorated.__defaults__ = getattr(fn, "__func__", fn).__defaults__
666 decorated.__wrapped__ = fn
667 return update_wrapper(decorated, fn)
668 else:
669 # this is the pytest hacky part. don't do a full update wrapper
670 # because pytest is really being sneaky about finding the args
671 # for the wrapped function
672 decorated.__module__ = fn.__module__
673 decorated.__name__ = fn.__name__
674 if hasattr(fn, "pytestmark"):
675 decorated.pytestmark = fn.pytestmark
676 return decorated
677
678 return decorate
679

Callers 1

async_testMethod · 0.70

Calls 5

inspect_getfullargspecFunction · 0.90
format_argspec_plusFunction · 0.90
_exec_code_in_envFunction · 0.70
extendMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected