Private
Public Access
0
0

refactor(multiple): complete Phase 6 Optional[T] elimination (batches 4 + 5)

Phase 6: Eliminate Optional[T] returns - BATCHES 4 + 5 (FINAL)
Before: 11 more Optional[T] returns removed (Phase 6 total: 30 of 30)
After:  0 (Phase 6 COMPLETE per VC5)
Delta:  -11 sites in this commit; cumulative -30/30 sites across all batches

Specific changes:
- src/diff_viewer.py:27: parse_hunk_header returns (-1, -1, -1, -1) sentinel
  on parse failure (2x `return None` -> `return (-1, -1, -1, -1)`)
- src/external_editor.py:23,84,97: get_editor / _find_vscode_common_paths /
  auto_detect_vscode all return TextEditorConfig or str with zero-init
  defaults (no longer Optional)
- src/external_editor.py:48: launch_diff_result sentinel check changed from
  `if not editor:` to `if not editor.name or not editor.path:`
- src/file_cache.py:549,608,646,705,799,858: 6 nested walk/deep_search
  helper functions now return tree_sitter.Node (root) instead of
  Optional[tree_sitter.Node] (None)
- src/models.py:691,728: TextEditorConfig defaults added (name="", path="");
  EMPTY_TEXT_EDITOR_CONFIG sentinel; ExternalEditorConfig.get_default
  returns EMPTY_TEXT_EDITOR_CONFIG when no editors configured
- src/file_cache.py:895: get_file_id returns "" (was Optional[str])

Test updates:
- tests/test_diff_viewer.py: still passes (parse_hunk_header tested)
- tests/test_external_editor.py:78,97: is None -> == "" check (config.get_default,
  get_editor for unknown name)

Verification:
- audit_weak_types --strict: OK (107 <= 112 baseline)
- py_check_syntax: OK on all changed files
- 85+ tests pass (test_file_cache, test_ast_parser, test_external_editor,
  test_diff_viewer, test_fuzzy_anchor, test_summary_cache, test_paths,
  test_persona_models, test_patch_modal, test_parallel_execution,
  test_track_state_persistence, test_session_logger_optimization,
  + 117 in broader run)

VC5 (Zero Optional[T] return types) PASSES:
  git grep -cE "-> Optional\\[" -- 'src/*.py' returns 0

PHASE 6 IS COMPLETE.

REMAINING WORK:
- Phase 7: Eliminate Any + dict[str, Any] in internal signatures (59+ sites)
- Phase 8: Final re-measure + verification
- Phase 9: Boundary layer audit (done)
This commit is contained in:
2026-06-26 05:16:25 -04:00
parent 4ca95551c0
commit 3a80b65692
5 changed files with 36 additions and 29 deletions
+12 -9
View File
@@ -20,12 +20,13 @@ class ExternalEditorLauncher:
"""
self.config = config
def get_editor(self, editor_name: Optional[str] = None) -> Optional[TextEditorConfig]:
def get_editor(self, editor_name: Optional[str] = None) -> TextEditorConfig:
"""
[C: tests/test_external_editor.py:TestExternalEditorLauncher.test_get_editor_by_name, tests/test_external_editor.py:TestExternalEditorLauncher.test_get_editor_returns_default, tests/test_external_editor.py:TestExternalEditorLauncher.test_get_editor_unknown_name]
"""
from src.models import EMPTY_TEXT_EDITOR_CONFIG
if editor_name:
return self.config.editors.get(editor_name)
return self.config.editors.get(editor_name) or EMPTY_TEXT_EDITOR_CONFIG
return self.config.get_default()
def build_diff_command(self, editor: TextEditorConfig, original_path: str, modified_path: str) -> List[str]:
@@ -40,7 +41,7 @@ class ExternalEditorLauncher:
[C: src/gui_2.py:App._open_patch_in_external_editor, tests/test_external_editor.py:TestExternalEditorLauncher.test_launch_diff_file_not_found, tests/test_external_editor.py:TestExternalEditorLauncher.test_launch_diff_missing_editor, tests/test_external_editor.py:TestExternalEditorLauncher.test_launch_diff_success]
"""
editor = self.get_editor(editor_name)
if not editor:
if not editor.name or not editor.path:
return Result(data=None, errors=[ErrorInfo(kind=ErrorKind.NOT_FOUND, message=f"No editor configured: {editor_name}", source="external_editor.launch_diff_result")])
cmd = self.build_diff_command(editor, original_path, modified_path)
try:
@@ -81,7 +82,7 @@ def _find_vscode_in_registry() -> Result[Optional[str]]:
return Result(data=None, errors=errors)
def _find_vscode_common_paths() -> Optional[str]:
def _find_vscode_common_paths() -> str:
candidates = [
r"C:\apps\Microsoft VS Code\Code.exe",
r"C:\Program Files\Microsoft VS Code\Code.exe",
@@ -91,16 +92,17 @@ def _find_vscode_common_paths() -> Optional[str]:
for path in candidates:
if os.path.exists(path):
return path
return None
return ""
def auto_detect_vscode() -> Optional[TextEditorConfig]:
def auto_detect_vscode() -> TextEditorConfig:
from src.models import EMPTY_TEXT_EDITOR_CONFIG
global _cached_vscode_config
if _cached_vscode_config is not None:
return _cached_vscode_config
vscode_result = _find_vscode_in_registry()
vscode_path = vscode_result.data if vscode_result.ok else None
if vscode_path is None:
vscode_path = vscode_result.data if vscode_result.ok else ""
if not vscode_path:
vscode_path = _find_vscode_common_paths()
if vscode_path:
_cached_vscode_config = TextEditorConfig(
@@ -108,7 +110,8 @@ def auto_detect_vscode() -> Optional[TextEditorConfig]:
path=vscode_path,
diff_args=["--new-window", "--diff"]
)
return _cached_vscode_config
return _cached_vscode_config
return EMPTY_TEXT_EDITOR_CONFIG
def get_default_launcher(config: Optional[Dict[str, Any]] = None) -> ExternalEditorLauncher: