Python: reject @executor on staticmethod/classmethod with clear error message - #1719
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the Python @executor decorator to properly detect and reject its misuse with @staticmethod and @classmethod through clear, actionable error messages. Previously, using @executor with these descriptors would fail with confusing errors because the decorator received a descriptor object instead of the actual function, causing async detection to fail.
Key Changes:
- Added explicit validation to reject
@staticmethod/@classmethodusage with helpful error messages - Introduced
_unwrap_descriptor()helper for defensive unwrapping in edge cases - Enhanced documentation to clarify the intended usage pattern (standalone functions vs. class-based executors)
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
python/packages/core/agent_framework/_workflows/_function_executor.py |
Added descriptor detection/rejection logic, unwrapping helper, and updated documentation to clarify supported usage patterns |
python/packages/core/tests/workflow/test_function_executor.py |
Added comprehensive tests validating rejection of @staticmethod/@classmethod and documenting async detection behavior with descriptors |
Contributor
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
Victor Dibia (victordibia)
approved these changes
Oct 27, 2025
Eric Zhu (ekzhu)
approved these changes
Oct 27, 2025
Evan Mattson (moonbox3)
removed this pull request from the merge queue due to a manual request
Oct 27, 2025
Reuben Bond (ReubenBond)
pushed a commit
to ReubenBond/agent-framework
that referenced
this pull request
Oct 28, 2025
… message (microsoft#1719) * reject executor on static method w clear error * Simplify * Cleanup
Aris Nguyen (arisng)
pushed a commit
to arisng/agent-framework
that referenced
this pull request
Feb 2, 2026
… message (microsoft#1719) * reject executor on static method w clear error * Simplify * Cleanup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
Addresses the underlying issue from a bug report about
@executorbeing used with@staticmethod. While this is not a supported use case, the decorator now properly detects and rejects this pattern with a clear, actionable error message.The
@executordecorator is designed for standalone module-level functions only. When mistakenly used with@staticmethodor@classmethod, it would previously fail with confusing errors or incorrect behavior because:@executorthen@staticmethod), the executor receives a descriptor object, not the functionasyncio.iscoroutinefunction()returnsFalsefor descriptor objects, even if the wrapped function is asyncThe fix is to have:
isinstance()check to detectstaticmethodandclassmethoddescriptorsValueErrorwith actionable guidance directing users to the correct pattern:@executorfor standalone functionsExecutorsubclass with@handleron instance methodsDefensive Unwrapping:
_unwrap_descriptor()helper to extract underlying callables from descriptorsDescription
Contribution Checklist