Skip to content

Don't fail compose signature when last function has no signature - #649

Open
heykav wants to merge 1 commit into
pytoolz:masterfrom
heykav:fix-compose-signature-no-return-sig
Open

heykav wants to merge 1 commit into
pytoolz:masterfrom
heykav:fix-compose-signature-no-return-sig

Conversation

@heykav

@heykav heykav commented Oct 11, 2026

Copy link
Copy Markdown

inspect.signature(compose(max, f)) raises ValueError: no signature found for builtin max even though f has 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 max as the last function. It fails before the change and passes after, and the existing tests still pass.

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 Wkhanex left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants