Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

singledispatchmethod.register fails with typing.Self annotation #130827

Copy link
Copy link
Open
@bvolkmer

Description

@bvolkmer
Issue body actions

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

No one assigned

    Labels

    stdlibPython modules in the Lib dirPython modules in the Lib dirtopic-typingtype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.