1. masklinn
  2. py.js
  3. Issues
Issue #12 new

Ensure data/non-data descriptor precedences are correctly handled

masklinn
repo owner created an issue

http://docs.python.org/reference/datamodel.html#descriptors

More info, from http://docs.python.org/howto/descriptor.html#invoking-descriptors

  • descriptors are invoked by the __getattribute__ method (ok so far)
  • overriding __getattribute__ prevents automatic descriptor calls (yup)
  • __getattribute__ is only available with new style classes and objects (whatever(
  • object.__getattribute__ and type.__getattribute__ make different calls to __get__. (might need to fix that)
  • data descriptors always override instance dictionaries.
  • non-data descriptors may be overridden by instance dictionaries.

Latter two are definitely not handled correctly.

http://hg.python.org/cpython/file/a61b3faa1c61/Objects/object.c#l1060

descr = cls.get(name)
f = None
if descr:
    f = getattr(descr, '__get__', None)
    if f and isDataDescriptor(descr): #  PyDescr_IsData
        return f(obj, cls)

res = instance.__dict__.get(name) # PyDict_GetItem(obj.__dict__, name)
if res: return res

if f: return f(obj, cls)

return descr

Comments (1)

  1. Log in to comment