PythonParser
classin packageklyn.code.python
public class PythonParser extends Object
└ PythonParser

Lightweight structural parser for Python source code (.py).

Extracts class, def, and async def declarations into a hierarchy of DeclarationNodes using Python indentation levels.

import klyn.code.python

src = "class Pipeline:\n    def execute(self, item: str) -> bool:\n        return True\n"
nodes = PythonParser.parseDeclarations(src)
assert nodes.size == 1
assert nodes[0].name == "Pipeline"
assert nodes[0].children.size == 1
assert nodes[0].children[0].name == "execute"
Inherited Properties
propertyInherited Properties from Object: type
Methods
Modifier and Type Member Description
public static parseDeclarations
parseDeclarations(source as String) as ArrayList<DeclarationNode>
Parses top-level Python classes and functions along with class methods.
Inherited Methods
methodInherited Methods from Object: deepCopy, fromJson, hash, toDict, toJson, toMap, toString, toXml