actions.py (horizon-20.1.0) | : | actions.py (horizon-20.1.1) | ||
---|---|---|---|---|
skipping to change at line 53 | skipping to change at line 53 | |||
This way actions can inherit from each other but still use | This way actions can inherit from each other but still use | |||
the class attributes DSL. Meaning, all attributes of Actions are | the class attributes DSL. Meaning, all attributes of Actions are | |||
defined as class attributes, but in the background, it will be used as | defined as class attributes, but in the background, it will be used as | |||
parameters for the initializer of the object. The object is then | parameters for the initializer of the object. The object is then | |||
initialized clean way. Similar principle is used in DataTableMetaclass. | initialized clean way. Similar principle is used in DataTableMetaclass. | |||
""" | """ | |||
def __new__(cls, name, bases, attrs): | def __new__(cls, name, bases, attrs): | |||
# Options of action are set as class attributes, loading them. | # Options of action are set as class attributes, loading them. | |||
options = {} | options = {} | |||
if attrs: | if attrs: | |||
options = attrs | # NOTE: It is required to create a new dict object | |||
# to avoid a recursive reference when no parent class | ||||
# has 'base_options' attribute. | ||||
options = dict(attrs) | ||||
# Iterate in reverse to preserve final order | # Iterate in reverse to preserve final order | |||
for base in bases[::-1]: | for base in bases[::-1]: | |||
# It actually throws all super classes away except immediate | # It actually throws all super classes away except immediate | |||
# superclass. But it's fine, immediate super-class base_options | # superclass. But it's fine, immediate super-class base_options | |||
# includes everything because superclasses was created also by | # includes everything because superclasses was created also by | |||
# this metaclass. Same principle is used in DataTableMetaclass. | # this metaclass. Same principle is used in DataTableMetaclass. | |||
if hasattr(base, 'base_options') and base.base_options: | if hasattr(base, 'base_options') and base.base_options: | |||
base_options = {} | base_options = {} | |||
# Updating options by superclasses. | # Updating options by superclasses. | |||
End of changes. 1 change blocks. | ||||
1 lines changed or deleted | 4 lines changed or added |