mirror of
https://mau.dev/maunium/synapse.git
synced 2024-10-01 01:36:05 -04:00
Fix @tag_args for non-methods (#17604)
The decorator assumed we were always wrapping function methods
This commit is contained in:
parent
f1a1c7fc53
commit
b4d95409fb
1
changelog.d/17604.misc
Normal file
1
changelog.d/17604.misc
Normal file
@ -0,0 +1 @@
|
|||||||
|
Add support to `@tag_args` for standalone functions.
|
@ -1032,13 +1032,13 @@ def tag_args(func: Callable[P, R]) -> Callable[P, R]:
|
|||||||
def _wrapping_logic(
|
def _wrapping_logic(
|
||||||
_func: Callable[P, R], *args: P.args, **kwargs: P.kwargs
|
_func: Callable[P, R], *args: P.args, **kwargs: P.kwargs
|
||||||
) -> Generator[None, None, None]:
|
) -> Generator[None, None, None]:
|
||||||
# We use `[1:]` to skip the `self` object reference and `start=1` to
|
for i, arg in enumerate(args, start=0):
|
||||||
# make the index line up with `argspec.args`.
|
if argspec.args[i] in ("self", "cls"):
|
||||||
#
|
# Ignore `self` and `cls` values. Ideally we'd properly detect
|
||||||
# FIXME: We could update this to handle any type of function by ignoring the
|
# if we were wrapping a method, but that is really non-trivial
|
||||||
# first argument only if it's named `self` or `cls`. This isn't fool-proof
|
# and this is good enough.
|
||||||
# but handles the idiomatic cases.
|
continue
|
||||||
for i, arg in enumerate(args[1:], start=1):
|
|
||||||
set_tag(SynapseTags.FUNC_ARG_PREFIX + argspec.args[i], str(arg))
|
set_tag(SynapseTags.FUNC_ARG_PREFIX + argspec.args[i], str(arg))
|
||||||
set_tag(SynapseTags.FUNC_ARGS, str(args[len(argspec.args) :]))
|
set_tag(SynapseTags.FUNC_ARGS, str(args[len(argspec.args) :]))
|
||||||
set_tag(SynapseTags.FUNC_KWARGS, str(kwargs))
|
set_tag(SynapseTags.FUNC_KWARGS, str(kwargs))
|
||||||
|
Loading…
Reference in New Issue
Block a user