This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author dabeaz
Recipients dabeaz
Date 2013-01-08.18:43:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1357670592.25.0.470525675752.issue16894@psf.upfronthosting.co.za>
In-reply-to
Content
Suppose you subclass a dictionary:

class mdict(dict):
    def __getitem__(self, index):
        print('Getting:', index)
        return super().__getitem__(index)

Now, suppose you define a function and perform these steps that reassign the function's attribute dictionary:

>>> def foo():
...     pass
... 
>>> foo.__dict__ = mdict()
>>> foo.x = 23
>>> foo.x          # Observe: No output from overridden __getitem__
23
>>> type(foo.__dict__)
<class '__main__.mdict'>
>>> foo.__dict__
{'x': 23}
>>> 

Carefully observe that access to foo.x does not invoke the overridden __getitem__() method in mdict.  Instead, it just directly accesses the default __getitem__() on dict. 

Admittedly, this is a really obscure corner case.  However, if the __dict__ attribute of a function can be legally reassigned, it might be nice for inheritance to work ;-).
History
Date User Action Args
2013-01-08 18:43:12dabeazsetrecipients: + dabeaz
2013-01-08 18:43:12dabeazsetmessageid: <1357670592.25.0.470525675752.issue16894@psf.upfronthosting.co.za>
2013-01-08 18:43:12dabeazlinkissue16894 messages
2013-01-08 18:43:11dabeazcreate