Skip to content

Commit 92f5166

Browse files
committed
Method Check
When compiling a method should only try to compile callable attributes when they are class methods.
1 parent 867d89e commit 92f5166

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

ngcsimlib/_src/parser/contextTransformer.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import ast
2+
import inspect
23

34
from ngcsimlib._src.context.contextAwareObjectMeta import ContextAwareObjectMeta
45
from ngcsimlib._src.global_state.manager import global_state_manager
@@ -83,7 +84,10 @@ def visit_Attribute(self, node):
8384
if callable(stateVal):
8485
method_name = f"{self.obj.context_path.replace(':', '_')}_{node.attr}"
8586
new_node = ast.copy_location(ast.Name(id=method_name, ctx=node.ctx), node)
86-
self.needed_methods[method_name] = node.attr
87+
if inspect.ismethod(stateVal):
88+
self.needed_methods[method_name] = node.attr
89+
else:
90+
self.needed_globals[method_name] = stateVal
8791
return ast.fix_missing_locations(new_node)
8892

8993
attr_name = f"{self.obj.context_path.replace(':', '_')}_{node.attr}"
@@ -131,7 +135,6 @@ def visit_Expr(self, node):
131135
if isinstance(node.value, ast.Call):
132136
call = node.value
133137
if isinstance(call.func, ast.Attribute) and call.func.attr == "set":
134-
135138
target = call.func.value
136139
target.ctx = ast.Store()
137140
if isinstance(target, ast.Subscript) and isinstance(target.value, ast.Name) and target.value.id == "ctx" and isinstance(target.slice, ast.Constant):

0 commit comments

Comments
 (0)