KEMBAR78
gh-119109: functools.partial.fallforward fix by dg-pb · Pull Request #119125 · python/cpython · GitHub
Skip to content

Conversation

@dg-pb
Copy link
Contributor

@dg-pb dg-pb commented May 17, 2024

#119109

I went with option 1. It is cleaner, faster and has a natural flow.

Before:

from functools import partial

def func(a, b, c=0):
    return a - b - c

p1 = partial(func, 1)

print(p1(2))    # -1
%timeit p1(2)   # 100 ns

p1.keywords['c'] = 1
print(p1(2))    # -2
%timeit p1(2)   # 234 ns

del p1.keywords['c']
print(p1(2))    # -1
%timeit p1(2)   # 144 ns

After:

p1 = partial(func, 1)

print(p1(2))    # -1
%timeit p1(2)   # 100 ns

p1.keywords['c'] = 1
print(p1(2))    # -2
%timeit p1(2)   # 234 ns

del p1.keywords['c']
print(p1(2))    # -1
%timeit p1(2)   # 100 ns

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.

3 participants