[ python-Bugs-1015792 ] __setitem__ for __dict__ ignored
SourceForge.net
noreply at sourceforge.net
Wed Aug 25 08:30:39 CEST 2004
Bugs item #1015792, was opened at 2004-08-25 00:50
Message generated for change (Comment added) made by rhettinger
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1015792&group_id=5470
Category: Python Interpreter Core
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Viktor A Danilov (vdanilov)
Assigned to: Nobody/Anonymous (nobody)
Summary: __setitem__ for __dict__ ignored
Initial Comment:
In python 2.3.3 this code cause assertion:
class d(dict):
_is_setted = None
def __setitem__(self, k, v):
self._is_setted = 1
class test:
def __init__(self):
self.__dict__ = d()
t = test()
t.x = 2
assert t.__dict__._is_setted == 1, 'no `__setitem__` calls'
----------------------------------------------------------------------
>Comment By: Raymond Hettinger (rhettinger)
Date: 2004-08-25 01:30
Message:
Logged In: YES
user_id=80475
Underneath the hood, test's setattr is accessing the
dictionary directly instead of going through its __setattr__
slot.
While this one is fixable, I'm not sure it's really a bug.
There are no documentation promises that things like setattr
won't make direct accesses to the underlying dictionary.
Python's implementation has tons of direct access code --
the reasons include clarity, speed, avoidance of hard to
debug code paths, or just not having been looked at in this way.
In any case, I would not have expected old style classes
like 'test' to know about new style subclasses.
For the use cases modeled after the OP's code, overiding
setattr in 'test' is likely the way to go.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1015792&group_id=5470
More information about the Python-bugs-list
mailing list