Skip to content

Commit 6255d12

Browse files
committed
Implement compile_docstring method in PythonParser for improved docstring handling
1 parent 46b8341 commit 6255d12

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

codetide/parsers/python_parser.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ def is_docstring(content :str)->bool:
5151
elif stripped.startswith("'''") and stripped.endswith("'''"):
5252
return True
5353
return False
54+
55+
@staticmethod
56+
def compile_docstring(raw :str, doctring :Optional[str]=None)->Optional[str]:
57+
if not doctring:
58+
return None
59+
60+
raw = raw.split(doctring)
61+
return f"{raw[0]}{doctring}"
5462

5563
@staticmethod
5664
def import_statement_template(importSatement :ImportStatement)->str:
@@ -369,7 +377,7 @@ def _process_function_definition(cls, node: Node, code: bytes, codeFile: CodeFil
369377
signature=signature,
370378
decorators=decorators,
371379
modifiers=modifiers,
372-
docstring=docstring,
380+
docstring=cls.compile_docstring(raw, docstring),
373381
raw=raw
374382
)
375383
)
@@ -380,13 +388,14 @@ def _process_function_definition(cls, node: Node, code: bytes, codeFile: CodeFil
380388
else:
381389
if raw is None:
382390
raw = cls._get_content(code, node)
391+
383392
codeFile.add_function(
384393
FunctionDefinition(
385394
name=definition,
386395
signature=signature,
387396
decorators=decorators,
388397
modifiers=modifiers,
389-
docstring=docstring,
398+
docstring=cls.compile_docstring(raw, docstring),
390399
raw=raw
391400
)
392401
)

0 commit comments

Comments
 (0)