Cannot use multiple inheritance with collections.abc.Buffer
and typing.Protocol
#104797
Labels
3.12
bugs and security fixes
3.13
bugs and security fixes
stdlib
Python modules in the Lib dir
topic-typing
type-bug
An unexpected behavior, bug, or error
Various stdlib classes are treated as protocols by type checkers, but are actually ABCs at runtime (for performance reasons). Examples include
contextlib.AbstractContextManager
andcollections.abc.Iterable
. These classes are special-cased intyping.py
to allow for multiple inheritance withtyping.Protocol
, so that the interface can be extended:collections.abc.Buffer
is a new-in-3.12 class that, likeAbstractContextManager
andIterable
, is an ABC at runtime but will be treated by type checkers as if it were aProtocol
. However, multiple inheritance withcollections.abc.Buffer
andtyping.Protocol
currently fails:I think
Buffer
should be special-cased in the same way asBuffer
andIterable
. It needs to be added to this mapping, I think:cpython/Lib/typing.py
Lines 1740 to 1746 in ddb1485
Cc. @JelleZijlstra for PEP-688
Linked PRs
The text was updated successfully, but these errors were encountered: