knit_script.knit_script_warnings.Knit_Script_Warning module

A module containing the base class for Knitting Script warnings.

This module provides the base warning class and specific warning types for the KnitScript programming language. These warnings alert developers to potentially problematic code patterns, configuration issues, and situations that may lead to unexpected behavior without causing program termination. The warning system helps developers write more robust knit script programs by identifying common pitfalls and questionable practices during execution.

exception Knit_Script_Warning(message, ks_element)[source]

Bases: RuntimeWarning

Base class for warnings caused by error-prone code in Knit Script.

The Knit_Script_Warning class serves as the foundation for all warning types in the KnitScript programming language. It extends Python’s RuntimeWarning to provide KnitScript-specific warning behavior and consistent message formatting. All specific KnitScript warning types inherit from this class, creating a hierarchical warning system that allows for both specific and general warning handling patterns.

This base class automatically prefixes warning messages with “KnitScript Warning:” to clearly identify KnitScript-related warnings and distinguish them from other system warnings. The warning system is designed to help developers identify potentially problematic code without stopping program execution.

message

The formatted warning message including the KnitScript warning prefix.

Type:

str

Parameters:
__init__(message, ks_element)[source]

Initialize the Knit_Script_Warning.

Creates a new KnitScript warning with the provided message. The message is automatically formatted with a KnitScript warning prefix and newline formatting for consistent warning display.

Parameters:
  • ks_element (KS_Element | None) – The KnitScript element that triggered the warning. Used to identify the location in the knitscript code.

  • message (str) – The warning message to display. This will be prefixed with “KnitScript Warning:” in the final formatted message.

add_note()

Exception.add_note(note) – add a note to the exception

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception Shadow_Variable_Warning(variable_name, ks_element=None)[source]

Bases: Knit_Script_Warning

Warning raised when a variable shadows another variable in an outer scope.

This warning is issued when a variable is defined in a local scope that has the same name as a variable in an outer scope, potentially hiding the outer variable and causing confusion. Variable shadowing can lead to unexpected behavior when developers intend to access the outer variable but inadvertently access the inner one instead.

Parameters:
__init__(variable_name, ks_element=None)[source]

Initialize the Shadow_Variable_Warning.

Parameters:
  • ks_element (KS_Element | None) – The KnitScript element that triggered the warning. Used to identify the location in the knitscript code.

  • variable_name (str) – The name of the variable that is shadowing another variable in an outer scope.

add_note()

Exception.add_note(note) – add a note to the exception

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception Shadows_Global_Variable_Warning(variable_name)[source]

Bases: Shadow_Variable_Warning

Warning raised when a variable shadows a global variable.

This specific type of shadow warning is issued when a local variable is defined with the same name as a global variable, potentially hiding the global variable. This is a more specific case of variable shadowing that focuses on global scope conflicts, which can be particularly problematic since global variables are often expected to be accessible throughout the program.

Parameters:

variable_name (str)

__init__(variable_name)[source]

Initialize the Shadows_Global_Variable_Warning.

Parameters:

variable_name (str) – The name of the variable that is shadowing a global variable.

add_note()

Exception.add_note(note) – add a note to the exception

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

exception Sheet_Beyond_Gauge_Warning(sheet, gauge)[source]

Bases: Knit_Script_Warning

Warning raised when the sheet setting exceeds the current gauge limits.

This warning occurs when attempting to set a sheet number that is outside the valid range for the current gauge configuration. Since sheet numbers must be between 0 and gauge-1, this warning is issued when automatic correction is applied to bring the sheet value back within acceptable bounds.

Parameters:
  • sheet (int | Sheet_Identifier)

  • gauge (int)

__init__(sheet, gauge)[source]

Initialize the Sheet_Beyond_Gauge_Warning.

Parameters:
  • sheet (int | Sheet_Identifier) – The sheet value that exceeds the gauge limits and triggered the warning.

  • gauge (int) – The current gauge setting that defines the valid range for sheet values.

add_note()

Exception.add_note(note) – add a note to the exception

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.