Prototype Module¶
This module contains the Prototype
that can be used to create inheritance on object level instead of class level.
-
class
knittingpattern.Prototype.Prototype(specification, inherited_values=())[source]¶ Bases:
objectThis class provides inheritance of its specifications on object level.
Throughout this class specification key refers to a
hashableobject to look up a value in the specification.-
__contains__(key)[source]¶ key in prototypeParameters: key¶ – a specification key Returns: whether the key was found in the specification Return type: bool
-
__getitem__(key)[source]¶ prototype[key]Parameters: key¶ – a specification key Returns: the value behind keyin the specificationRaises: KeyError – if no value was found
-
__init__(specification, inherited_values=())[source]¶ create a new prototype
Parameters: specification¶ – the specification of the prototype. This specification can be inherited by other prototypes. It can be a dictor an otherknittingpattern.Prototype.Prototypeor anything else that supports__contains__()and__getitem__()To look up a key in the specification it will be walked through
specificationinherited_valuesin order
However, new lookups can be inserted at before
inherited_values, by callinginherit_from().
-
__weakref__¶ list of weak references to the object (if defined)
-
get(key, default=None)[source]¶ Returns: the value behind keyin the specification. If no value was found,defaultis returned.Parameters: key¶ – a specification key
-
inherit_from(new_specification)[source]¶ Inherit from a
new_specificationParameters: new_specification¶ – a specification as passed to __init__()The
new_specificationis inserted before the firstinherited value.If the order is
after calling
prototype.inherit_from(new_specification)the lookup order isspecificationnew_specificationinherited_values
-