Skip to content

Preserve the signature of partials when decorating them - #195

Open
galafis wants to merge 1 commit into
micheles:masterfrom
galafis:fix-reused-partial-signature
Open

galafis wants to merge 1 commit into
micheles:masterfrom
galafis:fix-reused-partial-signature

Conversation

@galafis

@galafis galafis commented Oct 24, 2026

Copy link
Copy Markdown

Decorating a functools.partial currently applies update_wrapper directly to the original partial. This adds wrapped and changes inspect.signature(original) from the remaining arguments to the full underlying function signature. Decorating the same partial again then validates calls against the wrong signature and can reject valid calls.

Copy the partial and its attribute dictionary before copying wrapper metadata. The explicit dictionary copy also preserves partials that already have custom attributes without mutating their metadata. Add a regression that decorates the same partial twice, checks signatures and custom attributes, and calls both wrappers.

Validation on Python 3.12.14: the regression fails before the fix with (x, y) != (y). All 29 tests in tests/test.py pass after the fix; git diff --check passes.

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.

1 participant