Changed behavior of singledispatch in Python 3.12
Aperta
@AlexWaygood ci sta già lavorando.
Dal 20/3/2024.
3.12
3.13
stdlib
topic-typing
type-bug
- Lingua principale
- Python
- Stelle
- 77.2k
- Fork
- 35.9k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
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
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.
Valutazione
Questa issue non è ancora stata valutata.