[python] warn when an action declares a return value#835
Conversation
|
Hi, @vishnuprakaz, thanks for your work. Since Flink Agents 0.3 has been code freeze, I will review this PR after we cut release-0.3 branch. |
weiqingy
left a comment
There was a problem hiding this comment.
Thanks for taking this on — clean implementation of the TODO, and nice touch handling the stringized "None" annotation so the warning still fires correctly in modules that opt into from __future__ import annotations. One scope question inline.
| continue | ||
| inner, listen_events, target = marker | ||
| if target is None: | ||
| _warn_if_action_returns_value(name, inner) |
There was a problem hiding this comment.
The warning fires for @action-decorated methods here, but actions registered imperatively via add_action(name, events, func) flow through the agent.actions loop below (around line 311) and skip this check — so a plain Python callable with -> str passed to add_action hits the same silent-discard trap with no warning. Issue #834 scopes this to decorated methods, so this may be deliberate — is covering the add_action path worth a follow-up, or intentionally out of scope?
|
Thanks for review @weiqingy! Yes I scoped this to decorated @ action methods to match issue #834, so leaving out add_action was intentional. I'd prefer to keep this PR focused and cover the add_action path in a follow up I'll open a separate issue for it. Let me know if you'd rather I fold it into this PR instead. |
Sounds good. |
Linked issue: #834
Purpose of change
Actions communicate by sending events via
ctx.send_event(...); any value anaction returns is silently discarded by the framework. Previously this failed
quietly, so writing
return resultin an action did nothing with no error orwarning a confusing trap.
This implements the existing TODO in
plan/actions/action.pyby emitting a warning when an agent plan is built forany
@action-decorated method that declares a non-Nonereturn type, pointingthe user to
ctx.send_event(...). Warning only no change to execution behavior.Tests
Added two unit tests in
plan/tests/test_agent_plan.py:-> str) logs the warning, and-> Noneaction logs no warning.Verified locally with
pytestandruff check.API
No public API changes.
Documentation
doc-neededdoc-not-neededdoc-included