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.

classification
Title: Unable to explicitly subclass protocol when subclass has mixin requiring init
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.9
process
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: Nosy List: cmeyer
Priority: normal Keywords:

Created on 2021-10-13 02:09 by cmeyer, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg403782 - (view) Author: Chris Meyer (cmeyer) * Date: 2021-10-13 02:09
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?
msg403789 - (view) Author: Chris Meyer (cmeyer) * Date: 2021-10-13 02:59
This looks like it a regression specific to Python 3.9.7 and has been fixed.

https://bugs.python.org/issue45081
https://github.com/python/cpython/pull/28132.
History
Date User Action Args
2022-04-11 14:59:51adminsetgithub: 89617
2021-10-13 02:59:47cmeyersetstatus: open -> closed
resolution: duplicate
messages: + msg403789

stage: resolved
2021-10-13 02:09:30cmeyercreate