News for hackers. Stuff that matters.
Re:Frankenstein's `__init__` by vaylian on Saturday April 19, 2025 @01:19PM (#43737826)
Python has a trait-like system. It's called "abstract base classes": 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.

Re:Frankenstein's `__init__` by dragonwriter on Saturday April 19, 2025 @02:45PM (#43738492)
Protocols, too (they are defined on top of ABCs)

https://typing.python.org/en/latest/spec/protocol.html#proto...

Re:Frankenstein's `__init__` by gpderetta on Saturday April 19, 2025 @05:48PM (#43739726)
Protocols are definitely the closest thing to traits in Python. ABC are pretty much OoO interfaces.