virtual_knitting_machine.machine_components.machine_component_protocol module

Module containing the Machine_Component

class Machine_Component(*args, **kwargs)[source]

Bases: Machine_State_With_Policy, Protocol[Machine_LoopT]

property knitting_machine: Knitting_Machine_State[Machine_LoopT, Any]

Returns: Knitting_Machine_State: The knitting machine that owns this component.

property violation_policy: Knitting_Machine_Error_Policy

Returns: Knitting_Machine_Error_Policy: The policy for handling machine state errors.

property machine_specification: Knitting_Machine_Specification[Machine_LoopT]

Returns: Knitting_Machine_Specification[Machine_LoopT]: The machine specification of the machine associated with this component.

property machine_racking: int

Returns: int: The racking of the knitting machine.

property machine_is_all_needle_racked: bool

Returns: bool: True if the knitting machine is racked for all needle knitting.

property needle_count_of_machine: int

Returns: int: The number of needles on each bed of the knitting machine. Defaults to the bed size in the knitting machine specification.

property rightmost_slot_on_machine: int

Returns: int: The rightmost slot on this knitting machine. Defaults to the standard bed size in the knitting machine specification.

classmethod __class_getitem__(params)

Parameterizes a generic class.

At least, parameterizing a generic class is the main thing this method does. For example, for some generic class Foo, this is called when we do Foo[int] - there, with cls=Foo and params=int.

However, note that this method is also called when defining generic classes in the first place with class Foo(Generic[T]): ….

__init__(*args, **kwargs)
handle_violations(response_policy=None, handler=None)

Context manager that catches exceptions and routes them through the violation policy.

Parameters:
  • response_policy (ViolationResponse | Violation, optional) – The ViolationResponse policy for this code block. If given a Violation, the response will be the policy assigned to that violation in the violation policy. Defaults to the response will be the default response of the violation policy.

  • handler (Callable[..., Any], optional) – Optional handler to attempt before falling back to the policy response.

set_response_for(violation, response=None)

Sets the response for the given violation to the given response.

Parameters:
  • violation (Violation) – The violation to set the response for.

  • response (ViolationResponse, optional) – The response to set for the given violation. Defaults to the default response of this policy.