4 ms·
Python has a trait-like system. It's called "abstract base classes": https://docs.python.org/3/library/abc.html https://docs.python.org/3/library/abc.html The
by vaylian 2y ago
Python has a trait-like system. It's called "abstract base classes": https://docs.python.org/3/library/abc.html https://docs.python.org/3/library/abc.html
The abstract base class should use the @abstractmethod decorator for methods that the implementing class needs to implement itself.
Obviously, you can also use abstract base classes in other ways, but they can be used as a way to define traits/interfaces for classes.
- dragonwriter 2y agoProtocols, too (they are defined on top of ABCs) https://typing.python.org/en/latest/spec/protocol.html#protocols https://typing.python.org/en/latest/spec/protocol.html#proto...
- gpderetta 2y agoProtocols are definitely the closest thing to traits in Python. ABC are pretty much OoO interfaces.