thebjorn / pymagic

List of all Python magic methods
GNU Lesser General Public License v2.1
6 stars 5 forks source link

categorization tweaks #1

Open willp opened 8 years ago

willp commented 8 years ago

just my opinion, but i think the categorizations of dunder methods could be improved slightly: __bool__ is more of a typeconv than a representation __dir__ is more of a reflection than a representation __index__ is more of a container than a typeconv

again, just my opinion.

thebjorn commented 8 years ago

I'm inclined to agree with you on __index__ (based on my reading of https://docs.python.org/2.5/whatsnew/pep-357.html). For __bool__ and __dir__ I understand why you would think so -- and I might even agree, especially if constrained by the existing categories. The categories are taken verbatim from http://www.rafekettler.com/magicmethods.html, and I think the typeconv category is fundamentally flawed in a language where variables don't have type (the object has type, but you're not converting the object type..). E.g. __oct__ is not a conversion to an "octal" type, since it returns a string. Similarly for representation, there is a fundamental difference between methods such as __repr__ / __hash__ / __sizeof__ and __str__ / __unicode__ / __nonzero__ (__bool__)...