New submission from Arnaud Porterie: In the Data Model section of the documentation regarding descriptors invokations (http://docs.python.org/2/reference/datamodel.html#invoking-descriptors), it is said:
Note that descriptors are only invoked for new style objects or classes (ones that subclass object() or type()). However, it seems this restriction isn't enforced in practice: Python 2.7.4 (default, May 16 2013, 13:28:03) [GCC 4.2.1 Compatible Apple Clang 4.0 ((tags/Apple/clang-421.0.60))] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> class Desc(object): ... def __get__(self, obj, cls): ... return 'test' ... >>> class A: # Not inheriting object here ... desc = Desc() ... >>> A().desc 'test' I dived into CPython's code and saw no trace of a test for new-style classes in the descriptor invokation code path (down in classobject.c / instance_getattr2). Unfortunately, fixing this behavior doesn't seem trivial as class methods appear to be implemented as descriptor themselves. In other words, and from my understanding, restricting descriptor invokation to new-style objects and classes would prevent method calls on old-style classes. ---------- components: Interpreter Core files: desc.py messages: 189896 nosy: icecrime priority: normal severity: normal status: open title: Descriptors get invoked in old-style objects and classes type: behavior versions: Python 2.7 Added file: http://bugs.python.org/file30356/desc.py _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue18047> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com