Python is a beautiful, easy-to-read language. It’s also (usually) easy to write, most of the time. For the most part, it’s simple to make sure that your classes work well with the language by implementing several “magic methods”, but this gets tedious to do for a few of them.
A nice annotation that Kotlin comes with is the data annotation, which, when used on a class, will implement the equals(), hashCode(), and toString() methods for it, based on the properties passed in through the constructor. I wanted to do something similar to this in Python, since implementing __eq__, __hash__, __str__, and __repr__ can be tedious. Also, including such method definitions make your class look less appealing (those double-unders are a bit unsightly).
Let’s look at how this can be done. Continue Reading



