`singledispatchmethod.register` fails with `typing.Self` annotation
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza en functools.singledispatchmethod.register y reproduce el ejemplo mínimo del informe en Python 3.13. Comprueba el trabajo enlazado existente antes de continuar. Se considera terminado cuando se puede registrar un método que usa typing.Self sin provocar el TypeError por una anotación no válida, con cobertura de regresión para el ejemplo.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- backend
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 25/100