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

gh-119127: functools.partial placeholders by dg-pb · Pull Request #119303 · python/cpython · GitHub

Repository navigation

gh-119127: functools.partial placeholders - #119303

Closed
dg-pb wants to merge 119 commits into
python:mainfrom
dg-pb:implement-119127
Closed

dg-pb wants to merge 119 commits into
python:mainfrom
dg-pb:implement-119127

Conversation

dg-pb commented May 21, 2024 •
edited
Loading

Copy link
Copy Markdown
Contributor

As I already had implementation I though PR might be helpful for others to see and evaluate.

From all the different extensions of functools.partial I think this one is the best. It is relatively simple and exposes all missing functionality. Other partial extensions that I have seen lack functionality and would not provide complete argument ordering capabilities and/or are too complicated in relation to what they offer.

Implementation can be summarised as follows:
a) All trailing placeholders are removed. (Makes things simpler)
b) Throws exception if not all placeholders are filled on call
c) retains optimization benefits of application on other partial instances.

Performance penalty compared to current functools.partial is minimal for extension class. + 20-30 ns for initialisation and <4 ns when called with or without placeholders.

To put it simply, new functionality extends functools.partial so that it has flexibility of lambda / def approach (in terms of argument ordering), but call overhead is 2x smaller.

The way I see it is that this could only be justified if this extension provided completeness and no new functionality is going to be needed anywhere near in the future. I have thought about it and tried various alternatives and I think there is a good chance that this is the case. Personally, I don't think I would ever need anything more from partial class.

Current implementation functions reliably.

Comment thread Modules/_functoolsmodule.c Outdated

Copy link
Copy Markdown
Contributor

Could you add some tests? Or is that pointless without approval?

dg-pb commented May 21, 2024

Copy link
Copy Markdown
Contributor Author

I was thinking to wait for approval first.

This comment was marked as outdated.

dg-pb changed the title gn-119127: functools.partial placeholders gh-119127: functools.partial placeholders May 21, 2024
rhettinger self-assigned this May 21, 2024

dg-pb commented May 24, 2024

Copy link
Copy Markdown
Contributor Author

If this was accepted, the implementation is ready for review. Python and C versions are in sync and tests implemented.

dg-pb and others added 9 commits May 25, 2024 00:38
PR python#119321 added a comment about the magic number bump
but did not actually apply the new magic number.
…ython#119492)

``_fancy_replace()`` is no longer recursive. and a single call does a worst-case linear number of ratio() computations instead of quadratic. This renders toothless a universe of pathological cases. Some inputs may produce different output, but that's rare, and I didn't find a case where the final diff appeared to be of materially worse quality. To the contrary, by refusing to even consider synching on lines "far apart", there was more easy-to-digest locality in the output.

Copy link
Copy Markdown
Contributor

Please open a new clean PR against main. Make sure the diff against main is correct before opening the PR.

Copy link
Copy Markdown
Contributor

Thanks Erlend.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.


Back | FazBrowse Home | New Git URL