[Grok-dev] class-level versus instance-level attributes for schema

Philipp von Weitershausen philipp at weitershausen.de
Fri Oct 20 06:59:17 EDT 2006

Martijn Faassen wrote:
> Hi there,
> I see now that the __new__ in the schema support is gone. Reading the 
> code, I see that the attributes for the fields are added on class-level 
> instead of on instance-level. I wonder whether we can or should change 
> this.
> The current approach has the benefit of:
> * no __init__ necessary, so you can write your own
> An instance-level approach has the benefit of:
> * instance-level attributes are more inline with normal Python 
> approaches. class-level attributes are relatively rare.
> * we could hook in an __init__ that takes the schema names as (optional) 
> arguments.

And if not specified, it sets them as default values as specified by the 

> But we'd need to poke in a custom __init__ into the class during 
> grok-time, which could be considered icky (then again, poking in 
> class-level attributes could be considered as icky as well).

Why don't me make that the default grok.Model.__init__? In the rare case 
that people need to do their own initialization, they can choose to use 
super() (or not).

More information about the Grok-dev mailing list