refactor(scripts): Add strict type hints to utility scripts

This commit is contained in:
2026-02-28 18:58:53 -05:00
parent c368caf43a
commit 53c2bbfa81
6 changed files with 45 additions and 42 deletions

View File

@@ -1,14 +1,14 @@
import sys
import ast
def get_slice(filepath, start_line, end_line):
def get_slice(filepath: str, start_line: int | str, end_line: int | str) -> str:
with open(filepath, 'r', encoding='utf-8') as f:
lines = f.readlines()
start_idx = int(start_line) - 1
end_idx = int(end_line)
return "".join(lines[start_idx:end_idx])
def set_slice(filepath, start_line, end_line, new_content):
def set_slice(filepath: str, start_line: int | str, end_line: int | str, new_content: str) -> None:
with open(filepath, 'r', encoding='utf-8') as f:
lines = f.readlines()
start_idx = int(start_line) - 1
@@ -20,7 +20,7 @@ def set_slice(filepath, start_line, end_line, new_content):
with open(filepath, 'w', encoding='utf-8', newline='') as f:
f.writelines(lines)
def get_def(filepath, symbol_name):
def get_def(filepath: str, symbol_name: str) -> str:
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()
tree = ast.parse(content)
@@ -35,7 +35,7 @@ def get_def(filepath, symbol_name):
return f"{start},{end}{chr(10)}{slice_content}"
return "NOT_FOUND"
def set_def(filepath, symbol_name, new_content):
def set_def(filepath: str, symbol_name: str, new_content: str) -> None:
res = get_def(filepath, symbol_name)
if res == "NOT_FOUND":
print(f"Error: Symbol '{symbol_name}' not found in {filepath}")