Bugs item #1448042, was opened at 2006-03-11 17:49 Message generated for change (Comment added) made by tjreedy You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1448042&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Python Interpreter Core Group: None Status: Open Resolution: None Priority: 5 Submitted By: Michal Kwiatkowski (rubyjoker) Assigned to: Nobody/Anonymous (nobody) Summary: Defining a class with __dict__ brakes attributes assignment Initial Comment: When defining a class with __dict__ attribute, its instances can't rebind their __dict__ attributes. -------------------------------------------------- class C(object): __dict__ = {} obj = C() obj.a = object() import gc gc.get_referrers(obj.a) # => [{'a': <object object at 0x811d5b0>}] obj.__dict__ = {} # doesn't really bind new __dict__ vars(obj) # => {} object.__getattribute__(obj, '__dict__') # => {} object.__getattribute__(C, '__dict__') # => {..., but without "a"} obj.a # => <object object at 0x811d5b0> (no exception !) gc.get_referrers(obj.a) # => [{'a': <object object at 0x811d5b0>, '__dict__': {}}] -------------------------------------------------- Although neither class nor object has an attribute "a", it's still accessible. It's also not possible to rebind __dict__ in that object, as it gets inside real object attributes dictionary. This behaviour has been tested on Python 2.2, 2.3 and 2.4, but may as well affect earlier versions. ---------------------------------------------------------------------- >Comment By: Terry J. Reedy (tjreedy) Date: 2006-03-17 22:21 Message: Logged In: YES user_id=593130 To me, this falls under the category of 'don't do that'. http://docs.python.org/ref/id-classes.html 2.3.2 Reserved classes of identifiers __*__ System-defined names. These names are defined by the interpreter and its implementation ... To me, this means to use them in the manner specified or you get what you get. http://docs.python.org/ref/types.html#l2h-120 defines the internal usage of '__dict__'. There is, as far as I know, no specified usage for rebinding '__dict__'. So unless someone has a better idea that won't slow down proper usage, I would close this as 'invalid' or 'wont fix'. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1448042&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com