Open
Description
Bug report
Bug description:
When using singledispatchmethod
, the register
decorator function raises an exception if self
is annotated with typing.Self
:
TypeError: Invalid annotation for 'self'. typing.Self is not a class.
Minimal example:
from functools import singledispatchmethod
from typing import Self
class Foo:
@singledispatchmethod
def bar(self: Self, arg: int | str) -> int | str: ...
@bar.register
def _(self: Self, arg: int) -> int:
return arg
foo = Foo()
print(foo.bar(1))
The workaround is to remove the typing.Self
annotation for the _
function.
(Same for singledispatch
but that should not be used in that case anyway)
CPython versions tested on:
3.13
Operating systems tested on:
Linux
Linked PRs
Metadata
Metadata
Assignees
Labels
Python modules in the Lib dirPython modules in the Lib dirA feature request or enhancementA feature request or enhancement