From: SourceForge.net <no...@so...> - 2006-11-20 01:56:28
|
Bugs item #1506749, was opened at 2006-06-15 10:56 Message generated for change (Settings changed) made by cgroves You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=112867&aid=1506749&group_id=12867 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: Core >Group: targeted for 2.2beta2 Status: Open Resolution: None Priority: 5 Private: No Submitted By: Thilo Ernst (te0006) Assigned to: Nobody/Anonymous (nobody) Summary: instance __dict__ not assignable Initial Comment: when assigning to the __dict__ attribute of an object instance, the namespace dictionary (stringmap) is not replaced, but a '__dict__' key is created, and the new stringmap is assigned as a value to this key _in the existing namespace_. This happens both when using direct instance.__dict__=xyz assignment and when using the __setattr__() method of the class, of the 'object' class, or of the instance. The following code demonstrates the problem: ############### snip ########################### # let's define a simple class class C(object): pass c=C() c.attr1=42 print c.__dict__, type(c.__dict__) # we know Jython uses stringmaps as namespace # dicts, let's create a new stringmap object # (perhaps there is a simpler way) smap_type=type(c.__dict__) sm2=smap_type.__new__(smap_type) sm2['attr2']=0 # our first attempt to assign new stringmap to c.__dict__ c.__dict__=sm2 print '#1:', c.__dict__ #this obviously does not work, let's try a different method c.__setattr__('__dict__', sm2) print '#2:', c.__dict__ ############### snip ########################### CPython2.4 output: {'attr1': 42} <type 'dict'> #1: {'attr2': 0} #2: {'attr2': 0} Jython2.2a1 output: {'attr1': 42} <type 'stringmap'> #1: {'__dict__': {'attr2': 0}, 'attr1': 42} #2: {'__dict__': {'attr2': 0}, 'attr1': 42} This bug hampers many advanced uses of Python's meta-object protocol, such as the _threading_local.py module from CPython2.4 which allows to have "global" (syntactically, they indeed are) variables which in fact are stored on a per-thread basis. Which in turn is very useful when you have thread-specific "background state" information, such as the Request object in web programming. ---------------------------------------------------------------------- Comment By: Khalid Zuberi (kzuberi) Date: 2006-08-22 22:24 Message: Logged In: YES user_id=18288 newType() in PyType sets up __dict__ descriptors with null setters. Changing the setter to use a setDict method, and adding setDict to the various *Derived's (I guess via the code generation defined in src/templates) might make this work. Guess i'll give a try, though if someone has a better idea of how this should work i'd be happy to hear it. - kz ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=112867&aid=1506749&group_id=12867 |