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.


key in prototype

Parameters:key – a specification key
Returns:whether the key was found in the specification
Return type:bool


Parameters:key – a specification key
Returns:the value behind key in the specification
Raises: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 other knittingpattern.Prototype.Prototype or anything else that supports __contains__() and __getitem__()

To look up a key in the specification it will be walked through

  1. specification
  2. inherited_values in order

However, new lookups can be inserted at before inherited_values, by calling inherit_from().


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 a new_specification

Parameters:new_specification – a specification as passed to __init__()

The new_specification is inserted before the first inherited value.

If the order is

  1. specification
  2. inherited_values

after calling prototype.inherit_from(new_specification) the lookup order is

  1. specification
  2. new_specification
  3. inherited_values