knit_script.debugger.knitscript_debugger module

Module containing the Knit_Script_Debugger class.

class KnitScript_Debug_Mode(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Enumeration of stepping modes for the debugger

Continue = 'continue'
Step_Out = 'step-out'
Step_In = 'step-in'
Step_Over = 'step-over'
classmethod __contains__(member)

Return True if member is a member of this enum raises TypeError if member is not an enum member

note: in 3.12 TypeError will no longer be raised, and True will also be returned if member is the value of a member in this enum

classmethod __getitem__(name)

Return the member matching name.

classmethod __iter__()

Return members in definition order.

classmethod __len__()

Return the number of members (no aliases)

class Knit_Script_Debugger(debug_logger=None)[source]

Bases: Knit_Script_Debugger_Protocol

Attaches to knitscript interpreters to provide interactive debugging support through the python debugger.

machine_snapshots

Dictionary mapping knitout line numbers that were paused on to the state of the knitting machine at that line.

Type:

dict[int, Knitting_Machine_Snapshot]

__init__(debug_logger=None)[source]
property take_step_in: bool

Returns: bool: True if the debugger will stop at every execution and evaluation. False otherwise.

property take_step_over: bool

Returns: bool: True if the debugger will step to the next statement at the same level as the last pause. False otherwise.

property take_step_out: bool

Returns: bool: True if the debugger will continue until it reaches the parent statement/expression of the last time it was paused (or the end of the program). False otherwise.

property continue_to_end: bool

Returns: bool: True if the debugger will continue until the next breakpoint or end of the program. False otherwise.

property taking_snapshots: bool
Returns:

True if the debugger is set to take snapshots of the knitting machine state when paused. False, otherwise.

Return type:

bool

Notes

Snapshots are stored in the debugger’s machine_snapshots dictionary.

property stop_on_condition_errors: bool

Returns: bool: True if the debugger will stop when conditions trigger an exception. False, otherwise.

attach_context(context)[source]

Attaches the given interpreter to this debugger.

Parameters:

context (Knit_Script_Debuggable_Protocol) – The context of the knitout interpreter to attach to this debugger.

detach_context()[source]

Detaches the current interpreter from this debugger.

debug_statement(statement)[source]

Triggers a pause in the debugger based on the given statement and context.

Parameters:

statement (Statement) – The statement that triggered the pause and will be executed next.

debug_error(statement, exception)[source]

Pause the debugger because the given statement raised the given exception.

Parameters:
  • statement (Statement) – The statement that triggered the pause and will be executed next.

  • exception (BaseException) – The exception that triggered the pause and will be raised after this break.

enter_child_frame(scope)[source]

Enters a child frame with the given scope and makes it the main frame of the debugger.

Parameters:

scope (Knit_Script_Scope) – The scope to enter the child frame.

exit_to_parent_frame()[source]

Sets the current frame to the parent of the current frame. If there is no current frame, this is a No-op.

restart_frame(scope)[source]

Sets the frame to a new frame without external context initiated with the given scope.

Parameters:

scope (Knit_Script_Scope) – The scope to restart the current frame.

reset_debugger(reset_breaks=False, clear_snapshots=False)[source]

Resets the debugger to a new starting state with no prior information about where it was debugging. :param reset_breaks: If True, clears all prior information about breakpoints. Defaults to False. :type reset_breaks: bool, optional :param clear_snapshots: If True, clears all snapshots taken by the debugger. Defaults to False. :type clear_snapshots: bool, optional

set_breakpoint(line, condition=None)[source]

Sets a breakpoint with the optional condition for all statements/ expressions executed on the given knitscript line number. :param line: The line number of the knitscript line to set the breakpoint for. :type line: int :param condition: The optional condition used to determine if the breakpoint should be set. Defaults to no conditions on breaking. :type condition: Callable[[KnitScript_Debugger], bool], optional

clear_breakpoint(line)[source]

Removes any breakpoint at the given knitscript line number. :param line: The line number of the knitscript line to clear. :type line: int

enable_breakpoint(line)[source]

Enables any disabled breakpoint at the given knitscript line number. If there is no breakpoint and unconditioned breakpoint is enabled.

Parameters:

line (int) – The line number of the knitscript to enable the breakpoint for.

disable_breakpoint(line)[source]

Disable any breakpoint at the given knitscript line number. If there is no breakpoint, nothing happens. :param line: The line number of the knitscript to disable the breakpoint for. :type line: int

step()[source]

Sets the debugger to a step into every statement/ expression.

step_over()[source]

Sets the debugger to step at the same level as the last pause our out to a parent statement.

step_out()[source]

Sets the debugger to a step out to the parent statement/ expression or to the end of the program.

continue_knitscript()[source]

Sets the debugger to continue to the next breakpoint or end of the knitout program.

enable_snapshots()[source]

Sets the debugger to take snapshots of the knitting machine state whenever it pauses.

disable_snapshots()[source]

Sets the debugger to not take snapshots of the knitting machine state.

ignore_condition_exceptions()[source]

Sets the debugger to ignore condition exceptions and continue over these breakpoints.

pause_on_condition_exceptions()[source]

Sets the debugger to stop when a breakpoint condition raises an exception.

pause_on_statement(statement)[source]

Determines if the given statement should trigger the next pause in the debugger.

Parameters:

statement (KS_Element) – The next statement to consider pausing before.

Returns:

True if the debugger should pause before the given statement. False, otherwise.

Return type:

bool

add_statement_to_frame(statement)[source]

Adds the given statement to those that have been executed in the current frame. :param statement: The statement to add to the execution history. :type statement: KS_Element

print(message)[source]

Prints the given message to the debug logger. :param message: The message to print. :type message: str

print_user_guide()[source]

Helper function that prints out the KnitScript Debugger Breakpoint command line interface and Usage Guide.

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]): ….