New submission from Chris Meyer <[email protected]>:
If I make a explicit subclass of a protocol that also inherits from a mixin and
calls super() in order to initialize the mixin, I get the "Protocols cannot be
instantiated" exception.
This case arises when having a hierarchy of both protocols and concrete classes
that implement the protocols.
A simple example is:
import typing
class P(typing.Protocol):
def m1(self) -> None: ...
class M:
def __init__(self) -> None:
super().__init__()
self.o = True
class C(M, P):
def __init__(self) -> None:
super().__init__()
self.op = True
def m1(self) -> None:
pass
c = C()
I can resolve this in particular cases by not invoking super in the mixin or
putting a special no-super class in the hierarchy. However, that is not a
general solution and once the class hierarchy gets more complicated, it fails
to work.
Am I missing any known solution to this issue?
----------
components: Library (Lib)
messages: 403782
nosy: cmeyer
priority: normal
severity: normal
status: open
title: Unable to explicitly subclass protocol when subclass has mixin requiring
init
type: behavior
versions: Python 3.9
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue45454>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com