An object is an instance (or not)?

Ian Kelly ian.g.kelly at gmail.com
Thu Jan 29 16:48:26 CET 2015


On Thu, Jan 29, 2015 at 12:16 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> Besides, descriptors are
> handled by the metaclass, so we could write a metaclass that doesn't handle
> them.

Maybe this doesn't affect your argument, but they're actually handled
by the class's __getattribute__, not by the metaclass.

>>> class MyMeta(type):
...   def __getattribute__(cls, attr):
...     raise AttributeError(attr)
...
>>> class MyClass(metaclass=MyMeta):
...   @property
...   def spam(self):
...     return 42
...
>>> MyClass().spam
42
>>> class MyClass:
...   def __getattribute__(self, attr):
...     return type(self).__dict__[attr]
...   @property
...   def spam(self):
...     return 42
...
>>> MyClass().spam
<property object at 0x7f0603e70598>



More information about the Python-list mailing list