Skip to content

Commit d3000bb

Browse files
committed
Refactor: Add type hints to CodeParser AST visitor methods
1 parent 8d4e8ab commit d3000bb

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

src/pyob/pyob_code_parser.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,29 @@ def visit_Import(self, node: ast.Import) -> None:
3737
except Exception:
3838
pass
3939

40-
def visit_ImportFrom(self, node):
40+
def visit_ImportFrom(self, node: ast.ImportFrom) -> None:
4141
try:
4242
self.imports.append(ast.unparse(node))
4343
except Exception:
4444
pass
4545

46-
def visit_ClassDef(self, node):
46+
def visit_ClassDef(self, node: ast.ClassDef) -> None:
4747
self.classes.append(f"class {node.name}")
4848
old_class = self.current_class
4949
self.current_class = node.name
5050
for child in node.body:
5151
self.visit(child)
5252
self.current_class = old_class
5353

54-
def visit_FunctionDef(self, node):
54+
def visit_FunctionDef(self, node: ast.FunctionDef) -> None:
5555
self.handle_function(node)
5656

57-
def visit_AsyncFunctionDef(self, node):
57+
def visit_AsyncFunctionDef(self, node: ast.AsyncFunctionDef) -> None:
5858
self.handle_function(node)
5959

60-
def handle_function(self, node):
60+
def handle_function(
61+
self, node: ast.FunctionDef | ast.AsyncFunctionDef
62+
) -> None:
6163
args = []
6264
for arg in node.args.args:
6365
if self.current_class and arg.arg == "self":

0 commit comments

Comments
 (0)