11"""
2- Signal definition and registration for Cadence workflows.
2+ Signal definition for Cadence workflows.
33
4- This module provides functionality to define and register signal handlers
5- for workflows, similar to ActivityDefinition but for signals .
4+ This module provides the SignalDefinition class used internally by WorkflowDefinition
5+ to track signal handler metadata .
66"""
77
88import inspect
1616 Type ,
1717 TypeVar ,
1818 TypedDict ,
19- Unpack ,
20- overload ,
2119 get_type_hints ,
2220 Any ,
2321)
@@ -94,6 +92,9 @@ def wrap(
9492 """
9593 Wrap a function as a SignalDefinition.
9694
95+ This is an internal method used by WorkflowDefinition to create signal definitions
96+ from methods decorated with @workflow.signal.
97+
9798 Args:
9899 fn: The signal handler function to wrap
99100 opts: Options for the signal definition
@@ -102,7 +103,7 @@ def wrap(
102103 A SignalDefinition instance
103104
104105 Raises:
105- ValueError: If name is not provided in options or return type is not None
106+ ValueError: If return type is not None
106107 """
107108 name = opts .get ("name" ) or fn .__qualname__
108109 is_async = inspect .iscoroutinefunction (fn )
@@ -112,53 +113,6 @@ def wrap(
112113 return SignalDefinition (fn , name , params , is_async )
113114
114115
115- SignalDecorator = Callable [[Callable [P , T ]], SignalDefinition [P , T ]]
116-
117-
118- @overload
119- def defn (fn : Callable [P , T ]) -> SignalDefinition [P , T ]: ...
120-
121-
122- @overload
123- def defn (** kwargs : Unpack [SignalDefinitionOptions ]) -> SignalDecorator : ...
124-
125-
126- def defn (
127- fn : Callable [P , T ] | None = None , ** kwargs : Unpack [SignalDefinitionOptions ]
128- ) -> SignalDecorator | SignalDefinition [P , T ]:
129- """
130- Decorator to define a signal handler.
131-
132- Can be used with or without parentheses:
133- @signal.defn(name="approval")
134- async def handle_approval(self, approved: bool):
135- ...
136-
137- @signal.defn(name="approval")
138- def handle_approval(self, approved: bool):
139- ...
140-
141- Args:
142- fn: The signal handler function to decorate
143- **kwargs: Options for the signal definition (name is required)
144-
145- Returns:
146- The decorated function as a SignalDefinition instance
147-
148- Raises:
149- ValueError: If name is not provided
150- """
151- options = SignalDefinitionOptions (** kwargs )
152-
153- def decorator (inner_fn : Callable [P , T ]) -> SignalDefinition [P , T ]:
154- return SignalDefinition .wrap (inner_fn , options )
155-
156- if fn is not None :
157- return decorator (fn )
158-
159- return decorator
160-
161-
162116def _validate_signal_return_type (fn : Callable ) -> None :
163117 """
164118 Validate that signal handler returns None.
0 commit comments