A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2010-January/097189.html below:

[Python-Dev] Data descriptor doc/implementation inconsistency

[Python-Dev] Data descriptor doc/implementation inconsistency [Python-Dev] Data descriptor doc/implementation inconsistencyBenjamin Peterson benjamin at python.org
Mon Jan 11 01:07:35 CET 2010
Consider this program:

class Descr(object):
    def __init__(self, name):
        self.name = name
    def __set__(self, instance, what):
        instance.__dict__[self.name] = what

class X(object):
    attr = Descr("attr")

x = X()
print(x.attr)
x.attr = 42
print(x.attr)

It gives in output:

<__main__.Descr object at 0x7fe1c9b28150>
42

The documentation [1] says that Descr is a data descriptor because it
defines the __set__ method. It also states that data descriptors
always override the value in the instance dictionary. So, the second
line should also be the descriptor object according to the
documentation.

My question is: Is this a doc bug or a implementation bug? If the
former, it will be the description of a data descriptor much less
consistent, since it will require that a __get__ method be present,
too. If the latter, the fix may break some programs relying on the
ability to "cache" a value in the instance dictionary.

[1] http://docs.python.org/reference/datamodel#invoking-descriptors


-- 
Regards,
Benjamin

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4