Private
Public Access
fix(optional): NG2 fixed - 7 Optional[T] return-type violations migrated to Result[T]
This commit is contained in:
+14
-5
@@ -1283,11 +1283,20 @@ def ts_cpp_update_definition(path: str, name: str, new_content: str) -> str:
|
||||
|
||||
#region: Python AST
|
||||
|
||||
def _get_symbol_node(tree: ast.AST, name: str) -> Optional[ast.AST]:
|
||||
"""Helper to find an AST node by name (Class, Function, or Variable). Supports dot notation."""
|
||||
def _get_symbol_node_legacy_compat(tree: ast.AST, name: str) -> ast.AST | None:
|
||||
"""LEGACY: prefer _get_symbol_node_result() (returns Result[ast.AST])."""
|
||||
r = _get_symbol_node_result(tree, name)
|
||||
return r.data if r.ok else None
|
||||
|
||||
def _get_symbol_node(tree: ast.AST, name: str) -> ast.AST | None:
|
||||
"""Backward-compat alias for _get_symbol_node_legacy_compat."""
|
||||
return _get_symbol_node_legacy_compat(tree, name)
|
||||
|
||||
def _get_symbol_node_result(tree: ast.AST, name: str) -> Result[ast.AST]:
|
||||
"""Result-returning variant of _get_symbol_node."""
|
||||
parts = name.split(".")
|
||||
|
||||
def find_in_scope(scope_node: Any, target_name: str) -> Optional[ast.AST]:
|
||||
def find_in_scope(scope_node: Any, target_name: str) -> ast.AST | None:
|
||||
# scope_node could be Module, ClassDef, or FunctionDef
|
||||
body = getattr(scope_node, "body", [])
|
||||
for node in body:
|
||||
@@ -1305,9 +1314,9 @@ def _get_symbol_node(tree: ast.AST, name: str) -> Optional[ast.AST]:
|
||||
for part in parts:
|
||||
found = find_in_scope(current, part)
|
||||
if not found:
|
||||
return None
|
||||
return Result(data=None, errors=[ErrorInfo(kind=ErrorKind.NOT_FOUND, message=f"Symbol {part!r} not found in scope", source="mcp_client._get_symbol_node_result")])
|
||||
current = found
|
||||
return current
|
||||
return Result(data=current)
|
||||
|
||||
def py_get_skeleton(path: str) -> str:
|
||||
"""Returns a skeleton of a Python file (preserving docstrings, stripping function bodies).
|
||||
|
||||
Reference in New Issue
Block a user