[SQLObject] Solution to Re: Hook for .new() method?
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
|
From: Edmund L. <el...@in...> - 2003-07-05 19:44:14
|
I asked:
>What's the best way to hook some code into the .new()?
Ian Bicking wrote:
> Just with new, like:
>
> def new(cls, **kw):
> obj = super(cls).new(**kw)
> # ... do stuff ...
> return obj
> new = classmethod(new)
I wrote again:
>Hmmm... This doesn't seem to work. When I do this, I get
>an AttributeError:
>
> obj = super(cls).new(**kw)
> AttributeError: 'super' object has no attribute 'new'
>
>I know that there are some bugs in the super method of Python 2.2. Is
>this one of them? If so, how can I work around it?
To close on this... there is indeed a bug involving super() and
classmethods that is fixed in Python 2.2.1. That was one problem. The
other problem is that the code should have been:
Class MyClass(SQLObject):
def new(cls, **kw):
obj = super(MyClass, cls).new(**kw)
# ... do stuff ...
return obj
new = classmethod(new)
i.e., the super call must name MyClass (duh on my part, typo on Ian's,
I'm sure).
...Edmund.
|