GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||
GeezerVison is showing github.com — gh-130827: Support `typing.Self` annotations in `singledispatchmethod()` by ZeroIntensity · Pull Request #130829 · python/cpython Conversation
|
| # But, it shouldn't work on singledispatch() | ||
| with self.assertRaises(TypeError): | ||
| @test.register | ||
| def silly(self: typing.Self, arg: int | str) -> int | str: |
There was a problem 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.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Tomas R. <[email protected]>
There was an error while loading. Please reload this page.
|
@vstinner I'd like to get this fixed before 3.12 goes security-only next week. Would you mind reviewing? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
That's out of my domain expertise. @ambv would be a better reviewer for this task ;-) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Wait why would we want to change this in 3.12 at all? Seems like a new feature to me. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I agree, this is a new feature and should not be backported. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Agreed with Jelle, this is a feature best left for a new release. Otherwise it's too hard to guard against in user code. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Makes sense. I've updated the issue. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Bump. I'd like to land this one before the beta freeze. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
|
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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Wouldn't that break if it's named something other than |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I mean the first argument that's not conceptually |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This PR is stale because it has been open for 30 days with no activity. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I think @johnslavik has a different solution that he's been working on -- I'm going to close this in favor of his work. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.