FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

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

/ cpython Public

gh-119109: functools.partial.fallforward fix - #119125

Closed
dg-pb wants to merge 4 commits into
python:mainfrom
dg-pb:fix-issue-119109
Closed

gh-119109: functools.partial.fallforward fix#119125
dg-pb wants to merge 4 commits into
python:mainfrom
dg-pb:fix-issue-119109

Conversation

dg-pb commented May 17, 2024
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Contributor

#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

Comment thread Modules/_functoolsmodule.c Outdated
Comment thread Modules/_functoolsmodule.c Outdated
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL