`singledispatchmethod.register` fails with `typing.Self` annotation
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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
- gh-130829
- gh-143465
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia da functools.singledispatchmethod.register e riproduci l’esempio minimo del report su Python 3.13. Controlla il lavoro già collegato prima di procedere. Il lavoro è completato quando un metodo che usa typing.Self può essere registrato senza provocare il TypeError dovuto a un’annotazione non valida, con una copertura di regressione per l’esempio.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- backend
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100