docs: Note 'config' object shouldn't be accessed after initial load
Some checks failed
Build test / build (push) Has been cancelled
klipper3d deploy / deploy (push) Has been cancelled

Update Code_Overview.md to note that the config object should not be
stored after the "config loading phase".

Remove a few inadvertent cases where a 'config' object was stored
in module member variables.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2025-05-14 18:47:36 -04:00
parent 4d4b9684a5
commit d120a313b7
4 changed files with 6 additions and 4 deletions

View file

@ -286,6 +286,11 @@ The following may also be useful:
during the `load_config()` or "connect event" phases. Use either during the `load_config()` or "connect event" phases. Use either
`raise config.error("my error")` or `raise printer.config_error("my `raise config.error("my error")` or `raise printer.config_error("my
error")` to report the error. error")` to report the error.
* Do not store a reference to the `config` object in a class member
variable (nor in any similar location that may persist past initial
module loading). The `config` object is a reference to a "config
loading phase" class and it is not valid to invoke its methods after
the "config loading phase" has completed.
* Use the "pins" module to configure a pin on a micro-controller. This * Use the "pins" module to configure a pin on a micro-controller. This
is typically done with something similar to is typically done with something similar to
`printer.lookup_object("pins").setup_pin("pwm", `printer.lookup_object("pins").setup_pin("pwm",

View file

@ -321,7 +321,6 @@ class ADS1X1X_pin:
def __init__(self, chip, config): def __init__(self, chip, config):
self.mcu = chip.mcu self.mcu = chip.mcu
self.chip = chip self.chip = chip
self.config = config
self.invalid_count = 0 self.invalid_count = 0

View file

@ -9,7 +9,6 @@ from . import probe
class ScrewsTiltAdjust: class ScrewsTiltAdjust:
def __init__(self, config): def __init__(self, config):
self.config = config
self.printer = config.get_printer() self.printer = config.get_printer()
self.screws = [] self.screws = []
self.results = {} self.results = {}
@ -33,7 +32,7 @@ class ScrewsTiltAdjust:
default='CW-M3') default='CW-M3')
# Initialize ProbePointsHelper # Initialize ProbePointsHelper
points = [coord for coord, name in self.screws] points = [coord for coord, name in self.screws]
self.probe_helper = probe.ProbePointsHelper(self.config, self.probe_helper = probe.ProbePointsHelper(config,
self.probe_finalize, self.probe_finalize,
default_points=points) default_points=points)
self.probe_helper.minimum_points(3) self.probe_helper.minimum_points(3)

View file

@ -16,7 +16,6 @@ class ZThermalAdjuster:
self.printer = config.get_printer() self.printer = config.get_printer()
self.gcode = self.printer.lookup_object('gcode') self.gcode = self.printer.lookup_object('gcode')
self.lock = threading.Lock() self.lock = threading.Lock()
self.config = config
# Get config parameters, convert to SI units where necessary # Get config parameters, convert to SI units where necessary
self.temp_coeff = config.getfloat('temp_coeff', minval=-1, maxval=1, self.temp_coeff = config.getfloat('temp_coeff', minval=-1, maxval=1,