Kevin Dangoor wrote:
On 11/16/05, Ian Bicking <[EMAIL PROTECTED]> wrote:
Basically this:
class MyForm(TableForm):
foo1 = TextField()
foo2 = TextField()
Is exactly equivalent to:
MyForm = type(TableForm)('MyForm', (TableForm,), {'foo1':
TextField(), 'foo2': TextField})
this is probably a little too wacky, it turns out. Consider this case:
class TableForm(Subclassable):
def important_behavior(self):
print "foo"
TableForm = TableForm()
class MyForm(TableForm):
def important_behavior(self):
print "bar"
type(MyForm) -> TableForm
MyForm.important_behavior() -> TypeError (takes 1 argument, 0 given)
Not being able to override behavior would be an evil side effect of it
looking like a class but not actually being a class. There's probably
a way to bind the function to the instance, is there not?
import new, types
for attr, value in new_attrs.values():
if isinstance(value, types.FunctionType):
setattr(self, attr, new.instancemethod(value, self, self.__class__)
These are things that I think are worthy of exploration, but you have to
be ready to back them out if they don't pan out.
--
Ian Bicking / [EMAIL PROTECTED] / http://blog.ianbicking.org