GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-130827: Support `typing.Self` annotations in `singledispatchmethod()` by ZeroIntensity · Pull Request #130829 · python/cpython

Conversation

@ZeroIntensity

@ZeroIntensity ZeroIntensity commented Mar 4, 2025 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member
  • Issue: singledispatchmethod.register fails with typing.Self annotation #130827

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
ZeroIntensity added 2 commits March 4, 2025 06:56
@ZeroIntensity
pythongh-130827: Support typing.Self in singledispatchmethod()
d466dc4
@ZeroIntensity
Add blurb.
fd7e374
@ZeroIntensity ZeroIntensity added topic-typing needs backport to 3.12 only security fixes needs backport to 3.13 only security fixes labels Mar 4, 2025
@ZeroIntensity
ZeroIntensity requested a review from JelleZijlstra March 4, 2025 11:59
@ZeroIntensity
ZeroIntensity requested a review from rhettinger as a code owner March 4, 2025 11:59
@bedevere-app bedevere-app Bot added the awaiting review label Mar 4, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Mar 4, 2025
singledispatchmethod.register fails with typing.Self annotation #130827
Open
picnixz
picnixz reviewed Mar 4, 2025
View reviewed changes
Comment thread Lib/test/test_functools.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@ZeroIntensity @picnixz
Update Lib/test/test_functools.py
2e6b46f
Co-authored-by: Bénédikt Tran <[email protected]>
sobolevn
sobolevn reviewed Mar 4, 2025
View reviewed changes
Comment thread Lib/test/test_functools.py
# But, it shouldn't work on singledispatch()
with self.assertRaises(TypeError):
@test.register
def silly(self: typing.Self, arg: int | str) -> int | str:

@sobolevn sobolevn Mar 4, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ZeroIntensity ZeroIntensity Mar 4, 2025

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@sobolevn sobolevn Mar 4, 2025

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

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?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@ZeroIntensity ZeroIntensity Mar 4, 2025

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

sobolevn reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
tomasr8
tomasr8 reviewed Mar 4, 2025
View reviewed changes
Comment thread Lib/functools.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@ZeroIntensity @tomasr8
Update Lib/functools.py
f571ec7
Co-authored-by: Tomas R. <[email protected]>
JelleZijlstra
JelleZijlstra reviewed Mar 4, 2025
View reviewed changes
Comment thread Lib/functools.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

ZeroIntensity added 2 commits March 17, 2025 13:11
@ZeroIntensity
Add some checks for edge cases.
658d3fe
@ZeroIntensity
Fix code written with stupid nano.
2558b74
@ZeroIntensity
ZeroIntensity requested review from JelleZijlstra and sobolevn March 17, 2025 13:13
@ZeroIntensity
Fix indentation in comment.
f61d8a4
@ZeroIntensity

ZeroIntensity commented Apr 2, 2025

Copy link
Copy Markdown
Member Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Apr 2, 2025

Copy link
Copy Markdown
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
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JelleZijlstra

JelleZijlstra commented Apr 2, 2025

Copy link
Copy Markdown
Member

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sobolevn sobolevn removed needs backport to 3.12 only security fixes needs backport to 3.13 only security fixes labels Apr 2, 2025
@sobolevn

sobolevn commented Apr 2, 2025

Copy link
Copy Markdown
Member

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

ambv and ZeroIntensity reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ambv

ambv commented Apr 2, 2025

Copy link
Copy Markdown
Contributor

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
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ZeroIntensity

ZeroIntensity commented Apr 2, 2025

Copy link
Copy Markdown
Member Author

Makes sense. I've updated the issue.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ZeroIntensity
Merge branch 'main' into typing-self-singledispatch
65a9a95
@ZeroIntensity

ZeroIntensity commented Apr 29, 2025

Copy link
Copy Markdown
Member Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

JelleZijlstra
JelleZijlstra requested changes May 4, 2025
View reviewed changes

@JelleZijlstra JelleZijlstra left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this 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 the Self annotation is the wrong approach. The self argument may be annotated with Self, 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.

@register
def f(x, random_arg: str = ...):

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting changes and removed awaiting review labels May 4, 2025
@bedevere-app

bedevere-app Bot commented May 4, 2025

Copy link
Copy Markdown

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 phrase I 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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ZeroIntensity

ZeroIntensity commented May 4, 2025

Copy link
Copy Markdown
Member Author

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 than self?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@JelleZijlstra

JelleZijlstra commented May 4, 2025

Copy link
Copy Markdown
Member

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

ZeroIntensity reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@johnslavik johnslavik mentioned this pull request Oct 17, 2025
gh-84644: Don't single-dispatch on return types #140255
Closed
@github-actions

github-actions Bot commented Apr 22, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 22, 2026
@ZeroIntensity

ZeroIntensity commented Apr 22, 2026

Copy link
Copy Markdown
Member Author

I think @johnslavik has a different solution that he's been working on -- I'm going to close this in favor of his work.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ZeroIntensity ZeroIntensity closed this Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@tomasr8 tomasr8 tomasr8 left review comments
@picnixz picnixz picnixz left review comments
@JelleZijlstra JelleZijlstra JelleZijlstra requested changes
@rhettinger rhettinger Awaiting requested review from rhettinger rhettinger is a code owner
@sobolevn sobolevn Awaiting requested review from sobolevn

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting changes stale Stale PR or inactive for long period of time. topic-typing

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@ZeroIntensity @vstinner @JelleZijlstra @sobolevn @ambv @tomasr8 @picnixz
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.