Hacker News new | ask | show | jobs
by hobs 813 days ago
This is definitely bad advice and goes against the python data model. As far as I am concerned, dunder methods are key to idiomatic python.
1 comments

No, it is bad advice, and it is absolutely not idiomatic Python. The language specification reserves them to ensure new ones can be added in the future.

https://docs.python.org/3/reference/lexical_analysis.html#re...

This has been in the specification since, at latest, Python 2.0, and perhaps earlier.

Any you see defined outside the Python data model are entirely historical, written in contradiction to the spec. Many of them also can't be changed because there is so much code in the wild that depends on them.

*Do not define your own dunder methods!*