Skip to content

Commit

Permalink
feat: support docstring in runtime ast
Browse files Browse the repository at this point in the history
  • Loading branch information
Yazawazi committed May 18, 2024
1 parent 55af9f6 commit e52d3a3
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions backend/funix/decorator/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ def visit_FunctionDef(self, node: FunctionDef):
type_ignores=[],
)

node_doc_string = None
if node.body:
if isinstance(node.body[0], Expr) and isinstance(
node.body[0].value, Constant
):
node_doc_string = node.body[0].value.value

if node.name == "__init__":
# new_module.body[0].decorator_list[0].keywords = [
# keyword(arg="title", value=Constant(value=self._cls_name))
Expand All @@ -204,6 +211,8 @@ def visit_FunctionDef(self, node: FunctionDef):
)
)
]
if node_doc_string:
function.body.insert(0, Expr(value=Constant(value=node_doc_string)))
else:
if is_static_method:
function.body = [
Expand All @@ -219,6 +228,8 @@ def visit_FunctionDef(self, node: FunctionDef):
)
)
]
if node_doc_string:
function.body.insert(0, Expr(value=Constant(value=node_doc_string)))
else:
function.body = [
Assign(
Expand All @@ -242,6 +253,8 @@ def visit_FunctionDef(self, node: FunctionDef):
)
),
]
if node_doc_string:
function.body.insert(0, Expr(value=Constant(value=node_doc_string)))

globals()["__funix__module__"] = funix
globals()[self._cls_name] = self._cls
Expand Down

0 comments on commit e52d3a3

Please sign in to comment.