Skip to content

Add handle_response to normalize @on_method return values#15

Merged
Garulf merged 3 commits into
mainfrom
feature/handle-response
Jun 26, 2026
Merged

Add handle_response to normalize @on_method return values#15
Garulf merged 3 commits into
mainfrom
feature/handle-response

Conversation

@Garulf

@Garulf Garulf commented Jun 25, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds handle_response() function that transparently normalizes what @on_method-decorated functions return — no more boilerplate send_results() calls
  • Plugin methods can now yield Result(...), return a List[Result], or use generators; existing methods returning JsonRPCResponse or JsonRPCRequest continue to work unchanged
  • Introduces pyflowlauncher/types.py to hold the Method alias, breaking a latent circular import between result.py and plugin.py
  • Async generators are collected in EventHandler._await_maybe

New usage

@plugin.on_method
def query(q: str):
    yield Result(title="foo")
    yield Result(title="bar")

@plugin.on_method
async def query(q: str):
    yield Result(title="async result")

@plugin.on_method
def query(q: str):
    return [Result(title="a"), Result(title="b")]

Test plan

  • pytest tests/ — all 57 tests pass (15 new in tests/test_response.py)
  • Unit tests cover: single Result, List[Result], sync generator (single/multiple/list yields), JsonRPCRequest pass-through, JsonRPCResponse pass-through, None
  • Integration tests cover: @plugin.on_method with generator, single return, list return
  • Async generator tests: single yield, multiple yields, list yield

Garulf added 3 commits June 25, 2026 17:17
Plugin methods can now yield/return Result, List[Result], or use
generators without calling send_results() explicitly. Introduces
types.py to break the result.py→plugin.py circular import, and
response.py with handle_response() applied transparently in the
on_method wrapper. Async generators are handled in EventHandler.
@Garulf Garulf merged commit 3e08c2e into main Jun 26, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant