[Python-bugs-list] [ python-Bugs-775328 ] Setting metaclass descriptor doesn't intercept __get__
SourceForge.net
noreply@sourceforge.net
Tue, 22 Jul 2003 06:44:02 -0700
Bugs item #775328, was opened at 2003-07-21 23:16
Message generated for change (Settings changed) made by mwh
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=775328&group_id=5470
Category: Type/class unification
Group: Python 2.2.3
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: Mike C. Fletcher (mcfletch)
>Assigned to: Michael Hudson (mwh)
Summary: Setting metaclass descriptor doesn't intercept __get__
Initial Comment:
When working with metaclass descriptors (that is,
descriptors which live in metaclasses for the purpose
of providing properties on regular classes), if you
delete the descriptor from the meta-class, then re-set
the descriptor to re-enable the property-like
operation, subsequent accesses of the class' property
do not trigger the metaclass descriptor's __get__ method.
Tested on Python 2.2.3 on Win2K.
----------------------------------------------------------------------
>Comment By: Michael Hudson (mwh)
Date: 2003-07-22 14:43
Message:
Logged In: YES
user_id=6656
Mike, MetaProp is a non-data descriptor, and so overriden by
the contents of __dict__!
Adding a dummy __set__ to MetaProp makes the asserts pass.
----------------------------------------------------------------------
Comment By: Mike C. Fletcher (mcfletch)
Date: 2003-07-21 23:20
Message:
Logged In: YES
user_id=34901
Well, Mozilla crashes every time I try to upload the file,
so here's the code for the testing script...
class MetaProp(object):
def __init__(self, val):
self.val = val
def __get__(self, ob, cls=None):
for k in ob.__class__.__dict__:
if ob.__class__.__dict__[k] is self:
delattr(ob.__class__, k)
break
else:
raise Exception, 'not found'
self.val = self.val + 1
setattr(ob, k, self.val)
setattr(ob.__class__, k, self)
return self.val
class Meta(type):
p = MetaProp(1)
class C:
__metaclass__ = Meta
assert C.p == 2, """First increment didn't work (it does
work)"""
assert C.p == 3, """Second increment didn't work (it doesn't)"""
assert C.p == 4, """Third increment didn't work (never get
this far)"""
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=775328&group_id=5470