Class definitions, like function definitions, may be wrapped by one or more decorator expressions. The evaluation rules for the decorator expressions are the same as for functions. The result must be a class object, which is then bound to the class name.
So your class decorator should be able to create a new class with the required changes to the items in the dict_proxy and return that.
Laurence
(Disclaimer, I don't use Python 3 yet, so haven't tested this out).
Although the dict proxy object is read only you ca...
Michael Foord · 2010-06-16T12:27:25.778000
Although the dict proxy object is read only you can still set attributes on the class (having the same effect) - so I don't see why a class decorator shouldn't work. (That's before I've looked at what you're actually trying to do of course... :-)
Thanks, everybody, I figured there had to be a way...
Steve · 2010-06-16T13:36:25.307000
Thanks, everybody, I figured there had to be a way but I clearly didn't look hard enough.
You can use a class decorator and call setattr() i...
George · 2010-06-16T10:04:04.459000
You can use a class decorator and call setattr() instead of assigning directly to __dict__: http://gist.github.com/440413Although you can't modify __dict__ directly it...
Menno Smits · 2010-06-16T11:30:21.338000
Although you can't modify __dict__ directly it appears that setattr still works. Changing the tracing class decorator line:cdict[n] = traced(cdict[n])
to:
setattr(cls, n, traced(cdict[n]))
allows it to work with new-style classes (including Python 3).
From the docs: Class definitions, like function d...
Laurence Rowe · 2010-06-16T11:42:46.577000
From the docs:Class definitions, like function definitions, may be wrapped by one or more decorator expressions. The evaluation rules for the decorator expressions are the same as for functions. The result must be a class object, which is then bound to the class name.
So your class decorator should be able to create a new class with the required changes to the items in the dict_proxy and return that.
Laurence
(Disclaimer, I don't use Python 3 yet, so haven't tested this out).
Although the dict proxy object is read only you ca...
Michael Foord · 2010-06-16T12:27:25.778000
Although the dict proxy object is read only you can still set attributes on the class (having the same effect) - so I don't see why a class decorator shouldn't work. (That's before I've looked at what you're actually trying to do of course... :-)Thanks, everybody, I figured there had to be a way...
Steve · 2010-06-16T13:36:25.307000
Thanks, everybody, I figured there had to be a way but I clearly didn't look hard enough.Page 1 of 1
Back to post