diff --git a/conductor/code_styleguides/python.md b/conductor/code_styleguides/python.md index 8376e4c..6de7fe2 100644 --- a/conductor/code_styleguides/python.md +++ b/conductor/code_styleguides/python.md @@ -16,8 +16,9 @@ is processed by AI agents, while preserving readability for human review. - **Hard limit: 5 levels maximum.** - AI agents consistently misinterpret Python scope via indentation. This hard limit prevents deeply nested blocks that confuse model interpretation. -- **Enforcement:** Use ruff `max-c复-depth = 5` or flake8 `max-c复-depth = 5` in the project linter config. -- **Refactoring mandate:** Any block exceeding 3 levels must be extracted into a named function. Do not "work around" this with tricks—extract the logic. +- Classes and async handlers typically consume 1-2 levels before business logic begins, so 5 accommodates real-world usage patterns. +- **Enforcement:** Use ruff `[tool.ruff.lint.mccabe] max-complexity = 5` in the project linter config. +- **Refactoring mandate:** Any block exceeding 5 levels must be extracted into a named function. Do not "work around" this with tricks—extract the logic. - **Rationale:** GUI callbacks and async handlers naturally want to nest. This constraint forces extraction of deep logic into testable, named units. ## 2. Type Annotations diff --git a/pyproject.toml b/pyproject.toml index b0e4739..3ead2f4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,19 +52,21 @@ exclude = [ ] [tool.ruff.lint] +# Enable McCabe complexity check for nesting depth enforcement +select = ["E", "F", "W", "C90", "C4"] -# Enable standard rules -select = ["E", "F", "W"] # Ignore style choices that conflict with project's compact style ignore = [ "E701", # Multiple statements on one line (colon) "E702", # Multiple statements on one line (semicolon) "E402", # Module level import not at top of file - "E722", # Do not use bare `except` "E501", # Line too long "W291", # Trailing whitespace "W293", # Blank line contains whitespace ] +[tool.ruff.lint.mccabe] +max-complexity = 5 + diff --git a/src/gui_2.py b/src/gui_2.py index 91baec8..c272f1b 100644 --- a/src/gui_2.py +++ b/src/gui_2.py @@ -779,13 +779,11 @@ class App: [C: tests/test_shader_live_editor.py:test_shader_live_editor_renders] """ if self.show_windows.get('Shader Editor', False): - exp, opened = imgui.begin('Shader Editor', self.show_windows['Shader Editor']) - self.show_windows['Shader Editor'] = bool(opened) - if exp: - changed_crt, self.shader_uniforms['crt'] = imgui.slider_float('CRT Curvature', self.shader_uniforms['crt'], 0.0, 2.0) - changed_scan, self.shader_uniforms['scanline'] = imgui.slider_float('Scanline Intensity', self.shader_uniforms['scanline'], 0.0, 1.0) - changed_bloom, self.shader_uniforms['bloom'] = imgui.slider_float('Bloom Threshold', self.shader_uniforms['bloom'], 0.0, 1.0) - imgui.end() + with imgui_window('Shader Editor', self.show_windows['Shader Editor']) as window_result: + if window_result: + changed_crt, self.shader_uniforms['crt'] = imgui.slider_float('CRT Curvature', self.shader_uniforms['crt'], 0.0, 2.0) + changed_scan, self.shader_uniforms['scanline'] = imgui.slider_float('Scanline Intensity', self.shader_uniforms['scanline'], 0.0, 1.0) + changed_bloom, self.shader_uniforms['bloom'] = imgui.slider_float('Bloom Threshold', self.shader_uniforms['bloom'], 0.0, 1.0) def _render_history_window(self) -> None: if not self.show_windows.get('Undo/Redo History', False): diff --git a/src/imgui_scopes.py b/src/imgui_scopes.py index 9be3407..88a4be1 100644 --- a/src/imgui_scopes.py +++ b/src/imgui_scopes.py @@ -20,13 +20,13 @@ class ImGuiScope: self._entered = False def __enter__(self) -> bool | tuple: - result = self._begin_fn(*self._args, **self._kwargs) - if isinstance(result, tuple): - self._opened = result[0] + self._opened = self._begin_fn(*self._args, **self._kwargs) + if isinstance(self._opened, tuple): + self._entered = bool(self._opened[0]) + return self._opened else: - self._opened = result - self._entered = bool(self._opened) - return self._opened + self._entered = bool(self._opened) + return self._opened def __exit__(self, *args: object) -> bool: if self._entered: