[docs] [issue31735] Documentation incorrectly states how descriptors are invoked

Henk-Jaap Wagenaar report at bugs.python.org
Mon Oct 9 11:50:39 EDT 2017

Henk-Jaap Wagenaar <wagenaarhenkjaap at gmail.com> added the comment:

You get what you should get: when you print obj.d, Obj.d, you will get:

<property object at 0xDEADBEEF>

which is exactly what you expect:
- in the first case, you assigned a property object to the dictionary at obj.__dict__, so that's what you get back when you run obj.d.
- you defined a property on a class called d, and you get it when you run Obj.d

If you run print(Obj().d) you will get a TypeError: your lambda should read:

lambda self: print('called')

Properties should be added to the class not the instance, see https://stackoverflow.com/questions/1325673/how-to-add-property-to-a-class-dynamically and https://eev.ee/blog/2012/05/23/python-faq-descriptors/

nosy: +Henk-Jaap Wagenaar

Python tracker <report at bugs.python.org>

More information about the docs mailing list