Remove parent-resolution from wool.routine wrapper — Closes #118#119
Merged
conradbzura merged 4 commits intowool-labs:mainfrom Mar 25, 2026
Merged
Conversation
The _resolve() helper walked sys.modules to re-resolve the decorated function on every invocation. In nested dispatch this produced distinct class objects across workers, causing except clauses to silently miss re-raised exceptions. Removing _resolve eliminates the class-identity mismatch and the coupling to __module__ re-importability. @wool.routine now rejects classmethod/staticmethod descriptors and requires the correct decorator order (@classmethod @wool.routine).
953ca33 to
be8aced
Compare
conradbzura
commented
Mar 25, 2026
Add an info admonition to the wool.routine docstring explaining that @classmethod/@staticmethod must be the outer decorator when combined with @wool.routine, with a code example showing the correct order.
Flip decorator order in test fixtures and integration routines to match the new requirement (@classmethod/@staticmethod outer, @wool.routine inner). Add test_routine_with_descriptor_types to verify the ValueError guard rejects the old ordering.
be8aced to
5f01704
Compare
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.
Summary
Remove
_resolve()and its associatedclassmethod/staticmethoddescriptor handling fromwool.routine. The decorator now operates directly on the raw function passed to it, eliminating the per-invocationsys.moduleswalk that produced distinct class objects across workers and broke exception identity in nested dispatch scenarios.@wool.routinenow raisesValueErrorwhen applied to aclassmethodorstaticmethoddescriptor. The correct decorator order is@classmethod @wool.routine(descriptor outer, routine inner). An info admonition documenting this requirement is added to theroutine()docstring.Closes #118
Proposed changes
Remove _resolve and simplify dispatch internals
_resolve()walkedsys.modules[fn.__module__]usingfn.__qualname__to re-resolve the decorated function on every call. On spawned workers the re-imported module lives under__mp_main__, producing a different function object whose globals reference different class objects — breakingisinstancechecks andexceptclauses for user-defined exceptions in nested dispatch.With
_resolveremoved, the wrappers passfn(the original closure-captured function) directly to_dispatch,_stream, and_execute. Theparentparameter and theclassmethod/staticmethodbranch logic in_streamand_executeare also removed since the decorator now always receives the raw function.Add descriptor guard with clear error message
A new guard at the top of
routine()raisesValueError("@wool.routine must be applied before @classmethod/@staticmethod")when passed a descriptor object. This gives an actionable error message instead of the generic "Expected a coroutine function" that would otherwise fire.Update decorator order in test fixtures and integration routines
All
@routine @classmethod/@routine @staticmethodusages in test fixtures and integration routine definitions are flipped to the correct@classmethod @routine/@staticmethod @routineorder.Test cases
@routineapplied to a classmethod descriptorValueErrorwith message about correct order@routineapplied to a staticmethod descriptorValueErrorwith message about correct order@routineon various function types with dispatch enabled@routineon various function types with dispatch disabled