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-130827: Supporttyping.Self annotations insingledispatchmethod()#130829

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
ZeroIntensity wants to merge8 commits intopython:main
base:main
Choose a base branch
Loading
fromZeroIntensity:typing-self-singledispatch

Conversation

ZeroIntensity
Copy link
Member

@ZeroIntensityZeroIntensity commentedMar 4, 2025
edited by bedevere-appbot
Loading

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
# But, it shouldn't work on singledispatch()
with self.assertRaises(TypeError):
@test.register
def silly(self: typing.Self, arg: int | str) -> int | str:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Will'typing.Self' annotation work the same way?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Good question! It should, yeah.get_type_hints handles forward references.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Should we add a test case for that, maybe?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Possibly, but as long asget_type_hints is working it's probably fine.

sobolevn reacted with thumbs up emoji
Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
@ZeroIntensity
Copy link
MemberAuthor

@vstinner I'd like to get this fixed before 3.12 goes security-only next week. Would you mind reviewing?

@vstinner
Copy link
Member

@vstinner I'd like to get this fixed before 3.12 goes security-only next week. Would you mind reviewing?

That's out of my domain expertise.

@ambv would be a better reviewer for this task ;-)

ZeroIntensity reacted with thumbs up emoji

@JelleZijlstra
Copy link
Member

Wait why would we want to change this in 3.12 at all? Seems like a new feature to me.

@sobolevnsobolevn removed needs backport to 3.12only security fixes needs backport to 3.13bugs and security fixes labelsApr 2, 2025
@sobolevn
Copy link
Member

I agree, this is a new feature and should not be backported.

ambv and ZeroIntensity reacted with thumbs up emoji

@ambv
Copy link
Contributor

ambv commentedApr 2, 2025

Agreed with Jelle, this is a feature best left for a new release. Otherwise it's too hard to guard against in user code.

ZeroIntensity reacted with thumbs up emoji

@ZeroIntensity
Copy link
MemberAuthor

Makes sense. I've updated the issue.

@ZeroIntensity
Copy link
MemberAuthor

Bump. I'd like to land this one before the beta freeze.

Copy link
Member

@JelleZijlstraJelleZijlstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think special-casing theSelf annotation is the wrong approach. The self argument may be annotated withSelf, but it may also be annotated with e.g. a TypeVar or Annotated.

We should be ignoring annotations not on the basis of what the annotation is, but on the basis of what parameter they're on. I think the correct approach would be to figure out the name of the first non-self argument (i.e., the second argument for a method), then retrieve the annotation for that argument.

If I'm not mistaken, singledispatch also incorrectly (or at least unintuitively) handles cases where the annotation is on some later argument, but the first one is unannotated.

@registerdef f(x, random_arg: str = ...):

@bedevere-app
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phraseI have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@ZeroIntensity
Copy link
MemberAuthor

I think the correct approach would be to figure out the name of the first non-self argument

Wouldn't that break if it's named something other thanself?

@JelleZijlstra
Copy link
Member

I mean the first argument that's not conceptuallyself. We shouldn't look at the name.

ZeroIntensity reacted with thumbs up emoji

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

@tomasr8tomasr8tomasr8 left review comments

@picnixzpicnixzpicnixz left review comments

@JelleZijlstraJelleZijlstraJelleZijlstra requested changes

@rhettingerrhettingerAwaiting requested review from rhettingerrhettinger is a code owner

@sobolevnsobolevnAwaiting requested review from sobolevn

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

7 participants
@ZeroIntensity@vstinner@JelleZijlstra@sobolevn@ambv@tomasr8@picnixz

[8]ページ先頭

©2009-2025 Movatter.jp