From 087b2e0a22c205bad4b15955b18c2aba1370c996 Mon Sep 17 00:00:00 2001 From: Evgeniy Blinov Date: Mon, 8 Jan 2024 01:39:48 +0300 Subject: [PATCH] type hints --- astrologic/decorators/base.py | 1 + astrologic/decorators/inline.py | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/astrologic/decorators/base.py b/astrologic/decorators/base.py index 38baa5b..c7f6f85 100644 --- a/astrologic/decorators/base.py +++ b/astrologic/decorators/base.py @@ -57,6 +57,7 @@ def get_globals_by_function(self, function: Callable[..., Any]) -> Dict[str, Any module = importlib.import_module(module_name) except ModuleNotFoundError: return {} + result = {} for object_name in dir(module): _object = getattr(module, object_name) diff --git a/astrologic/decorators/inline.py b/astrologic/decorators/inline.py index 6b948de..eda8804 100644 --- a/astrologic/decorators/inline.py +++ b/astrologic/decorators/inline.py @@ -12,20 +12,22 @@ def change_tree(self, tree, original_function, function_text, *functions, **kwar all_original_names: Set[str] = self.get_all_names(tree) class VisiterCalls(ast.NodeTransformer): - def visit_Expr(_self, node): + def visit_Expr(_self, node: ast.Expr) -> Optional[Union[ast.AST, List[ast.AST]]]: try: value = node.value _node = node + if isinstance(value, ast.Call): node = value - if node.func.id in functions: - function_name = node.func.id + if node.func.id in functions: # type: ignore[attr-defined] + function_name = node.func.id # type: ignore[attr-defined] function_tree = self.get_function_tree(function_name, original_function.__module__) new_block, declarations = self.replace_names(all_original_names, function_tree, node) new_block = new_block.body[0].body return declarations + new_block else: return _node + except Exception: return node