Repository navigation
Conversation
Compose.__signature__ only needs the last function for the return annotation, but called inspect.signature on it unguarded. For builtins like max or set this raised ValueError, so inspect.signature(compose(max, f)) failed even though f has a normal signature. Fall back to no return annotation in that case.
Wkhanex
left a comment
There was a problem hiding this comment.
Checked 198e202 on CPython 3.12.14 with two non-introspectable final callables: builtin max (ValueError from inspection) and a callable whose __signature__ raises TypeError. In both cases, composition still ran correctly and retained every input parameter's kind, annotation and default, including positional-only, variadic and keyword-only parameters; the return annotation was empty as intended.
I also checked that an inspectable final callable keeps its return annotation and that a non-introspectable input callable still raises instead of fabricating a parameter signature. All 8 assertions passed; the base fails on max. The existing compose tests passed with 5 passed and 1 skipped. Full-suite and version-matrix coverage were not run.
Review prepared with Codex assistance; the checks described above were executed locally.
inspect.signature(compose(max, f))raisesValueError: no signature found for builtin maxeven thoughfhas a perfectly good signature.Compose.__signature__only uses the last function for the return annotation, so I wrapped that lookup in a try/except and fall back to no return annotation.I added a test that uses
maxas the last function. It fails before the change and passes after, and the existing tests still pass.