mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-06 05:17:15 +00:00
fix(plugins): keep a context keyword whose name only a positional-only first parameter shares
`def h(source, /, **kwargs)` and `def h(*session_id, **kwargs)` cannot take that name by keyword, so the context value belongs in kwargs. (Greptile re-review on #140997.)
This commit is contained in:
1 parent
9cfcfcc8d4
commit
5f274827ff
2 files changed
+6
-1
No files matched your search
@@ -23,7 +23,8 @@ def invoke_plugin_command(handler: Callable, raw_args: str, **context: Any) -> A
|
||||
# The first positional parameter receives raw_args whatever its name (``def h(source, **kw)``
|
||||
# must not get ``source`` twice).
|
||||
if parameters and parameters[0].kind is not inspect.Parameter.KEYWORD_ONLY:
|
||||
context = {k: v for k, v in context.items() if k != parameters[0].name}
|
||||
if parameters[0].kind is inspect.Parameter.POSITIONAL_OR_KEYWORD:
|
||||
context = {k: v for k, v in context.items() if k != parameters[0].name}
|
||||
parameters = parameters[1:]
|
||||
if any(p.kind is inspect.Parameter.VAR_KEYWORD for p in parameters):
|
||||
return handler(raw_args, **context)
|
||||
|
||||
@@ -21,8 +21,12 @@ def test_handlers_get_only_the_context_they_declare():
|
||||
def first_named_source(source, **kwargs): # raw_args fills `source`; it is never passed twice
|
||||
return source, sorted(kwargs)
|
||||
|
||||
def first_positional_only(source, /, **kwargs): # its name is not a keyword: kwargs keep source
|
||||
return source, kwargs["source"]
|
||||
|
||||
assert invoke_plugin_command(legacy, "a", **CONTEXT) == ("a",)
|
||||
assert invoke_plugin_command(named, "a", **CONTEXT) == ("a", "sid", "telegram")
|
||||
assert invoke_plugin_command(catch_all, "a", **CONTEXT) == ("a", CONTEXT)
|
||||
assert invoke_plugin_command(positional_only, "a", **CONTEXT) == ("a", None)
|
||||
assert invoke_plugin_command(first_named_source, "a", **CONTEXT) == ("a", ["platform", "session_id", "session_key"])
|
||||
assert invoke_plugin_command(first_positional_only, "a", **CONTEXT) == ("a", "src")
|
||||
Reference in new issue
Block a user