This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author cmeyer
Recipients cmeyer
Date 2021-10-13.02:09:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1634090970.26.0.320360946482.issue45454@roundup.psfhosted.org>
In-reply-to
Content
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?
History
Date User Action Args
2021-10-13 02:09:30cmeyersetrecipients: + cmeyer
2021-10-13 02:09:30cmeyersetmessageid: <1634090970.26.0.320360946482.issue45454@roundup.psfhosted.org>
2021-10-13 02:09:30cmeyerlinkissue45454 messages
2021-10-13 02:09:30cmeyercreate