[ python-Bugs-1448042 ] Defining a class with __dict__ brakes attributes assignment
SourceForge.net
noreply at sourceforge.net
Sat Mar 18 09:29:58 CET 2006
Bugs item #1448042, was opened at 2006-03-11 22:49
Message generated for change (Comment added) made by gbrandl
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: Closed
>Resolution: Wont Fix
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: Georg Brandl (gbrandl)
Date: 2006-03-18 08:29
Message:
Logged In: YES
user_id=849994
Agreed with Terry.
----------------------------------------------------------------------
Comment By: Terry J. Reedy (tjreedy)
Date: 2006-03-18 03: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
More information about the Python-bugs-list
mailing list