'Python multiple inheritance from class and protocol
In Python, I have two protocols, one of which inherits from the other:
class SupportsFileOperations(Protocol):
...
class SupportsMediaOperations(SupportsFileOperations):
...
I then have a couple of concrete classes that implement these protocols, and one inherits from the other.
class File(SupportsFileOperations):
...
class MediaFile(File, SupportsMediaOperations):
def __init__(self):
File.__init__(self)
My question is, is calling File.__init__(self) in the MediaFile constructor the correct way to initialize this? I'm not sure how multiple inheritance works with protocols.
Thanks!
Solution 1:[1]
You can simply add Protocol in the child class:
from typing import Protocol
class SupportsFileOperations(Protocol):
...
class SupportsMediaOperations(SupportsFileOperations, Protocol):
...
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jean-Francois T. |
