mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
0d6b9d61a5
* Python: Fix Executor handler type checking with __future__ annotations (#3898) Use typing.get_type_hints() in _validate_handler_signature to resolve string annotations from `from __future__ import annotations`. This mirrors the fix applied to FunctionExecutor in #2308. When __future__ annotations are enabled, type annotations are stored as strings. The handler decorator was passing these strings directly to validate_workflow_context_annotation, which uses typing.get_origin and returns None for strings, causing a ValueError. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Address PR review feedback for #3898: improve error handling and test coverage - Wrap typing.get_type_hints() in try/except to provide a descriptive ValueError mentioning the handler name when annotations cannot be resolved - Strengthen bare context test to assert output_types and workflow_output_types - Add test for @handler(input=..., output=...) with future annotations covering the skip_message_annotation branch - Add test for union-type context annotations with future annotations Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Narrow exception catch and add test for unresolvable annotations (#3898) - Narrow except clause from bare Exception to (NameError, AttributeError, TypeError) to avoid masking unexpected errors. - Add test_handler_unresolvable_annotation_raises to verify that a handler with a forward-reference to a non-existent type raises ValueError with the expected message. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix #3898: fall back to raw annotations when get_type_hints fails When typing.get_type_hints(func) raises NameError (unresolvable forward ref), AttributeError, RecursionError, or any other exception, fall back to the raw parameter annotations instead of raising a ValueError. This matches the suggestion from @moonbox3 on PR #4317. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix test to match new fallback behavior when get_type_hints fails (#3898) The code now falls back to raw string annotations instead of raising 'Failed to resolve type annotations'. A ValueError is still raised when the raw string ctx annotation is not a valid WorkflowContext type, so update the test to match on ValueError without checking the message. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Apply pyupgrade: remove unnecessary string annotation quote * Add noqa for intentionally undefined name in annotation test --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
0d6b9d61a5
ยท
2026-02-27 02:59:57 +00:00
History