Skip to content

Commit

Permalink
fix: class function do not use new app
Browse files Browse the repository at this point in the history
  • Loading branch information
Yazawazi committed Jul 15, 2024
1 parent 548cd1b commit d676f30
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions backend/funix/decorator/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from typing import Any

import funix
from funix.config.switch import GlobalSwitchOption
from funix.app import get_new_app_and_sock_for_jupyter
from funix.hint import WrapperException
from funix.session import get_global_variable, set_global_variable
Expand Down Expand Up @@ -83,7 +84,11 @@ def __init__(self, cls_name: str, funix_: Any, cls: Any):
self._cls_name = cls_name
self._cls = cls
self._imports = []
self.class_app, self.class_sock = get_new_app_and_sock_for_jupyter()
if GlobalSwitchOption.IN_NOTEBOOK:
self.class_app, self.class_sock = get_new_app_and_sock_for_jupyter()
else:
self.class_app = None
self.class_sock = None

self.open_function = False

Expand Down Expand Up @@ -140,7 +145,11 @@ def visit_FunctionDef(self, node: FunctionDef):
value=Name(id="__funix__module__", ctx=Load()), attr="funix", ctx=Load()
),
args=[],
keywords=[
keywords=[],
)

if GlobalSwitchOption.IN_NOTEBOOK:
funix_decorator.keywords.append(
keyword(
arg="app_and_sock",
value=Tuple(
Expand All @@ -151,8 +160,7 @@ def visit_FunctionDef(self, node: FunctionDef):
ctx=Load(),
),
)
],
)
)

for decorator in node.decorator_list:
if hasattr(decorator, "id") and decorator.id == "staticmethod":
Expand Down Expand Up @@ -276,6 +284,7 @@ def visit_FunctionDef(self, node: FunctionDef):
globals()["class_app"] = self.class_app
globals()["class_sock"] = self.class_sock
code = unparse(new_module)
print(code)
try:
exec(
code,
Expand Down

0 comments on commit d676f30

Please sign in to comment.