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:
object
This class provides inheritance of its specifications on object level.
Throughout this class specification key refers to a
hashable
object to look up a value in the specification.-
__contains__
(key)[source]¶ key in prototype
Parameters: 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 key
in 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 dict
or an otherknittingpattern.Prototype.Prototype
or anything else that supports__contains__()
and__getitem__()
To look up a key in the specification it will be walked through
specification
inherited_values
in 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 key
in the specification. If no value was found,default
is returned.Parameters: key¶ – a specification key
-
inherit_from
(new_specification)[source]¶ Inherit from a
new_specification
Parameters: new_specification¶ – a specification as passed to __init__()
The
new_specification
is inserted before the firstinherited value
.If the order is
after calling
prototype.inherit_from(new_specification)
the lookup order isspecification
new_specification
inherited_values
-