Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-124652: partialmethod simplifications#124788

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
dg-pb wants to merge18 commits intopython:main
base:main
Choose a base branch
Loading
fromdg-pb:gh-124652-partialmethod

Conversation

dg-pb
Copy link
Contributor

@dg-pbdg-pb commentedSep 30, 2024
edited
Loading

  1. it is now untangled frompartial (makes use ofpartial instead of containing any complexities of partial)
  2. it has no need for any special-casing ininspect
  3. its performance is now reasonable (for standard methods andpartial objects)

partialmethod Benchmarks:

Setup

S="from functools import partialmethod, Placeholder@staticmethoddef s(a, b):    pass@classmethoddef c(self, a, b):    passdef m(self, a, b):    passclass D:    def __get__(self, obj, cls=None):        return (lambda a, b: None)d = D()class A:    @staticmethod    def s(a, b):        pass    @classmethod    def c(self, a, b):        pass    def m(self, a, b):        pass    d = D()    ps = partialmethod(s, 1)    pc = partialmethod(c, 1)    pm = partialmethod(m, 1)    pd = partialmethod(d, 1)a = A()"

C1='partialmethod(s, 1)'# staticmethodC2='partialmethod(c, 1)'# classmethodC3='partialmethod(m, 1)'# instance methodC4='partialmethod(d, 1)'# unknown descriptorC5='A.ps(2)'C6='A.pc(2)'C7='a.pm(2)'C8='a.pd(2)'NOTE: construction costfor standard methods is obfuscated       as they are constructed and cached on 1st call.#  BEFORE | AFTER---------------------------#-----------------$PYEXE -m timeit -s$S$C1#  920 ns |  390 ns$PYEXE -m timeit -s$S$C2# 1000 ns |  420 ns$PYEXE -m timeit -s$S$C3#  900 ns |  440 ns$PYEXE -m timeit -s$S$C4# 1000 ns |  600 ns---------------------------#-----------------$PYEXE -m timeit -s$S$C5# 1300 ns |  330 ns$PYEXE -m timeit -s$S$C6#  830 ns |  390 ns$PYEXE -m timeit -s$S$C7#  800 ns |  390 ns$PYEXE -m timeit -s$S$C8# 1300 ns |  890 ns

@rhettingerrhettinger removed their request for reviewSeptember 30, 2024 16:31
@dg-pbdg-pbforce-pushed thegh-124652-partialmethod branch froma04c14f tod217592CompareOctober 6, 2024 16:56
@dg-pb
Copy link
ContributorAuthor

Removed keyword Placeholder restriction from this and will issue a separate PR after. Felt like too much is packed into 1 PR.

@eendebakpt
Copy link
Contributor

@dg-pb Is this PR still relevant or have you opened PRs for the different components? If so, can we close this one?

@dg-pb
Copy link
ContributorAuthor

It is still relevant.
On my part this is ready for review.
Givenpartial.Placeholder has been merged recently and not in production I wasn't sure if splitting is necessary.

I could factor "allowing trailing placeholders" into a separate one if it is preferred.

@eendebakpt
Copy link
Contributor

It is still relevant. On my part this is ready for review. Givenpartial.Placeholder has been merged recently and not in production I wasn't sure if splitting is necessary.

I could factor "allowing trailing placeholders" into a separate one if it is preferred.

I have not looked at all the changes in detail, but the PR seems big and that could be a reason this PR has not yet been reviewed. In the description at least 3 changes are mentioned (allowing placeholders, performance, refactor forpartialmethod). If possible, I would advice to split the PR into multiple PRs.

erlend-aasland reacted with thumbs up emoji

@dg-pb
Copy link
ContributorAuthor

dg-pb commentedJan 4, 2025
edited
Loading

at least 3 changes are mentioned

There are 2 really.

Performance benefit is a consequence of "allowing trailing placeholders".

I don't mind making changes, splitting as desired etc, but I would like these to be called by reviewer. Otherwise, I already have experience by trying to guess what reviewer might prefer, making changes per suggestions of others, etc and when final reviewer comes he desires to be different again and I need to keep changing things more times than necessary.

And either way these would need to be considered at the same time. I.e. allowing or not allowing trailing placeholders are both ok. There is a slight advantage for allowing them as it makes it a bit more flexible and explicit. While looking atpartial from the POV of using it on methods, the advantages and rationale for allowing them can be seen more clearly putting it on a favourable side (at least this is my conclusion).

Also, if I split now, then I have PRs hanging on unmerged code.

the PR seems big

It isn't that big. Most of it is Pure Python rewrite ofpartialmethod and the implementation is much simpler to follow than the previous one.

@dg-pb
Copy link
ContributorAuthor

As this series ofpartial related PRs started slowly moving, the path became a bit clearer and splitting this into 2 seems to be the best option to me now. Will do that shortly.

erlend-aasland reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@eendebakpteendebakpteendebakpt left review comments

@tomasr8tomasr8tomasr8 left review comments

@serhiy-storchakaserhiy-storchakaAwaiting requested review from serhiy-storchaka

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@dg-pb@eendebakpt@tomasr8

[8]ページ先頭

©2009-2025 Movatter.jp