refactor(scripts): Add strict type hints to utility scripts
This commit is contained in:
@@ -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}")
|
||||
|
||||
Reference in New Issue
Block a user