Changed behavior of singledispatch in Python 3.12
Aberta
@AlexWaygood já está trabalhando nisso.
Desde 20/3/2024.
3.12
3.13
stdlib
topic-typing
type-bug
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 36k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
Bug report
Bug description:
It seems the behavior of functools.singledispatch changed in Python 3.12 in situations where a typing.Protocol is involved.
When executing the following code on 3.12, MyClass no longer gets dispatched as via the default but as MyProtocol. The problem seems to be that issubclass now behaves differently when called on protocols. The issue was noticed here where it caused downstream problems.
from typing import Protocol
from functools import singledispatch
class MyProtocol(Protocol):
pass
class MyClass:
pass
s = singledispatch(lambda x: "default")
s.register(MyProtocol, lambda x: "protocol")
print(s(MyClass)) # yields "default" on 3.11 but "protocol" on 3.12
CPython versions tested on:
3.11, 3.12
Operating systems tested on:
macOS
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Avaliação
Esta issue ainda não foi avaliada.