From: SourceForge.net <no...@so...> - 2007-03-08 10:59:30
|
Bugs item #1676293, was opened at 2007-03-08 08:09 Message generated for change (Comment added) made by h_eriksson You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=112867&aid=1676293&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: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Henrik Eriksson (h_eriksson) Assigned to: Nobody/Anonymous (nobody) Summary: metaclass __init__ dct reference Initial Comment: The dct object that gets passed to a metaclass' __init__ method seems to point to the actual __dict__ of the class beeing created. I guess it should be a copy? The following code breaks with a KeyError since delattr removes the attribute from dct. def __init__(cls, name, bases, dct): # ...snip dctnames = dct.keys() if name.endswith("__doc"): if hasattr(cls, name): delattr(cls, name) val = dct[name] # ...snip ---------------------------------------------------------------------- >Comment By: Henrik Eriksson (h_eriksson) Date: 2007-03-08 11:59 Message: Logged In: YES user_id=1652173 Originator: YES As you (Samule) say this seems like an obscure implementation detail and I'm not sure it should be fixed... I could try reasoning with the CP folks and see if they can fix it in their code instead. ---------------------------------------------------------------------- Comment By: Henrik Eriksson (h_eriksson) Date: 2007-03-08 11:46 Message: Logged In: YES user_id=1652173 Originator: YES Sorry for the confusing description. I should have referred to the mail-thread about "metaclasses in jython" on jython-dev (Charlie asked me to post the bug). Hehe... the code is from CherryPy 3. ---------------------------------------------------------------------- Comment By: Samuele Pedroni (pedronis) Date: 2007-03-08 11:21 Message: Logged In: YES user_id=61408 Originator: NO now I see, there is indeed a copy involved in CPython, but is what is stored on the type which is a copy. This is honestly an obscure implementation detail, and not copying is faster. Easy enough to do the CPython thing tough. Still whoever wrote that sort of code that depends on this should feel dirty :) . ---------------------------------------------------------------------- Comment By: Samuele Pedroni (pedronis) Date: 2007-03-08 10:47 Message: Logged In: YES user_id=61408 Originator: NO why guessing when you can check? I still don't understand what's the problem, too little information Python 2.4.3 (#1, Apr 7 2006, 10:54:33) [GCC 4.0.1 (Apple Computer, Inc. build 5250)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> class T(type): ... def __init__(self, name, bases, dct): ... global d ... d = dct ... >>> class X(object): ... __metaclass__ = T ... global d1 ... d1 = locals() ... >>> d1 is d True ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=112867&aid=1676293&group_id=12867 |