Skip to content
Vasili edited this page Sep 11, 2015 · 9 revisions

When user defines its own application class following happens:

  1. Before class has been defined: all definitions which belong to the class are wrapped to _UnboundDefinition;
  2. After class has been defined: class is registered as application class (instead base class).

On main call:

  1. Instance of registered application class is created (call to class method __new__ happens)
  2. Before it has been initialized (before call to __init__) whole set of instances for definitions are created and bound to the application instance

Definition Binding

Creation of definition instance is postponed from the point where it appears in source code to a moment when instance of its parent class has been created.

_UnboundDefinition captures class of definition itself and all its initialization arguments right before its parent class defined (actually at the point where definition appears in the source code). It tries to extract value of "name" argument by position or keyword. If argument does not have value (but __init__ method have the argument) or its value is auto library marks the definition as requires automatic name.

When parent's instance is created _UnboundDefinition creates wrapped definition and binds it to the parent.

Another option for binding

Creation of definition instance should happen right in the point it is placed (before parent class creation). Binding happens later - after parent class is created and definition instance should be bound not to parent instance but to parent class. On binding definition should get name attribute. It should be of string (or unicode) type and be not empty. Its value should be a name of option in command line.

Clone this wiki locally