Skip to content

gh-130827: Support typing.Self annotations in singledispatchmethod() #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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

ZeroIntensity
Copy link
Member

@ZeroIntensity ZeroIntensity commented Mar 4, 2025

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
Member Author

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
Member Author

Choose a reason for hiding this comment

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

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

Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
@ZeroIntensity
Copy link
Member Author

@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 commented Apr 2, 2025

@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 ;-)

@JelleZijlstra
Copy link
Member

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

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

sobolevn commented Apr 2, 2025

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

@ambv
Copy link
Contributor

ambv commented Apr 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
Copy link
Member Author

Makes sense. I've updated the issue.

@ZeroIntensity
Copy link
Member Author

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

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.

7 participants