@@ -83,30 +83,34 @@ def with_signature(
8383) -> Callable [P , R ] | Callable [[Callable [P , R ]], Callable [P , R ]]:
8484 """Add a signature to a function of type `f(*args, **kwargs)` (decorator).
8585
86- The user-described view (parameter names, kinds, and any type strings
87- passed via `args` / `kwargs`) is written to the wrapper's
88- `__signature__`. The wrapper's `__annotations__` advertises the
89- `*args, **kwargs` forwarder shape instead — the wrapper genuinely
86+ The user-described view (parameter names, kinds, and any type hints passed
87+ via the dict form of `args` / `kwargs` or via `return_annotation`) is written
88+ to the wrapper's `__signature__`. The wrapper's `__annotations__` advertises
89+ the `*args, **kwargs` forwarder shape instead — the wrapper genuinely
9090 accepts anything at the Python level, and only the wrapped function
9191 expects the user-typed arguments. Runtime type checkers (beartype,
9292 typeguard) read `__annotations__` and therefore treat the wrapper as
9393 permissive; `dags.get_annotations` recovers the user view from
9494 `__signature__` via its built-in args/kwargs-mismatch fallback.
9595
96- Caveats: The created signature only contains the names of arguments and whether
97- they are keyword-only. There is no way of setting default values or type hints.
96+ The created signature carries argument names, whether each argument is
97+ keyword-only, and—when the dict form of `args`/`kwargs` is used or
98+ `return_annotation` is set—parameter and return type hints (written to
99+ `__signature__`, as described above). Default values cannot be set.
98100
99101 Args:
100102 func: The function to be decorated. Should take `*args`
101103 and `**kwargs` as only arguments.
102104 args: If a list, the names of positional or keyword arguments. If a dict,
103- the names of positional or keyword arguments and their types as strings.
105+ the names of positional or keyword arguments mapped to their type hints
106+ (as strings).
104107 kwargs: If a list, the names of keyword only arguments. If a dict,
105- the names of keyword only arguments and their types as strings.
108+ the names of keyword only arguments mapped to their type hints (as
109+ strings).
106110 enforce: Whether the signature should be enforced or just
107111 added to the function for introspection. This creates runtime
108112 overhead.
109- return_annotation: The return annotation. By default, the return annotation is
113+ return_annotation: The return annotation. By default, it is
110114 `inspect.Parameter.empty`.
111115
112116 Returns:
0 commit comments