dunder-docs (was Python is DOOMED! Again!)

Marko Rauhamaa marko at pacujo.net
Tue Feb 3 05:38:39 EST 2015


Devin Jeanpierre <jeanpierreda at gmail.com>:

> It isn't mystical. There are differences in semantics of defining
> methods inside or outside of a class that apply in certain situations
> (e.g. super(), metaclasses). You have cherrypicked an example that
> avoids them.

It's slightly sad that Python exposes the two-level attribute lookup. It
would be more elegant if, conceptually, all methods were retrieved from
the object's attribute dict. That way, the class would be simply a
mundane optimization trick instead of a metaphysical entity.

   A class instance has a namespace implemented as a dictionary which is
   the first place in which attribute references are searched. When an
   attribute is not found there, and the instance’s class has an
   attribute by that name, the search continues with the class
   attributes.
   [<URL: https://docs.python.org/3/reference/datamodel.html>]


Marko



More information about the Python-list mailing list