knit_script.debugger.debug_protocol module

Module containing the Knit_Script_Debugger_Protocol

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

Bases: Protocol

Protocol for debuggable elements in knitscript execution (i.e., statements).

property line_number: int

Returns: int: The line number where this element appears in the source file.

property file_name: str | None

Returns: str | None: The file name of the knitscript program this was parsed from or None if the program was passed as a string.

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)
class Knit_Script_Debuggable_Protocol(*args, **kwargs)[source]

Bases: Protocol

A protocol for any debuggable value

debugger: Knit_Script_Debugger_Protocol | None
variable_scope: Knit_Script_Scope
report_locals()[source]
Returns:

A tuple containing the following values from the state of the debugged protocol: * The current state of the knitting machine. * The active yarn-carrier set or None if no carrier set is active. * The current sheet that the machine is set to. * The gauge that the machine is set to.

Return type:

tuple[Knitting_Machine, Yarn_Carrier_Set | None, Sheet_Identifier, int]

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)
class Knit_Script_Debugger_Protocol(*args, **kwargs)[source]

Bases: Protocol

A protocol for a knitscript debugging process.

attach_context(debuggable)[source]

Attaches the given interpreter to this debugger.

Parameters:

debuggable (Knit_Script_Debuggable_Protocol) – The debuggable process to attach to.

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 (KS_Element) – 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 (KS_Element) – 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. :param scope: The scope to restart the current frame. :type scope: Knit_Script_Scope

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

print(message)[source]

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

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)