-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
d466dc4
fd7e374
2e6b46f
f571ec7
658d3fe
2558b74
f61d8a4
65a9a95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3362,6 +3362,30 @@ def _(item, arg: bytes) -> str: | |
self.assertEqual(str(Signature.from_callable(A.static_func)), | ||
'(item, arg: int) -> str') | ||
|
||
def test_typing_self(self): | ||
# gh-130827: typing.Self with singledispatchmethod() didn't work | ||
class Foo: | ||
@functools.singledispatchmethod | ||
def bar(self: typing.Self, arg: int | str) -> int | str: ... | ||
|
||
@bar.register | ||
def _(self: typing.Self, arg: int) -> int: | ||
return arg | ||
|
||
|
||
foo = Foo() | ||
self.assertEqual(foo.bar(42), 42) | ||
|
||
@functools.singledispatch | ||
def test(self: typing.Self, arg: int | str) -> int | str: | ||
pass | ||
# 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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good question! It should, yeah. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add a test case for that, maybe? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Possibly, but as long as |
||
pass | ||
|
||
ZeroIntensity marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
class CachedCostItem: | ||
_cost = 1 | ||
|
Uh oh!
There was an error while loading. Please reload this page.