MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / decorate

Function decorate

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

Source from the content-addressed store, hash-verified

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

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