MCPcopy Create free account
hub / github.com/Glyphack/enderpy / ast2json

Function ast2json

compat/ast_python.py:75–87  ·  view source on GitHub ↗
(node)

Source from the content-addressed store, hash-verified

73
74
75def ast2json(node):
76 assert isinstance(node, AST)
77 to_return = dict()
78 to_return["_type"] = node.__class__.__name__
79 for attr in dir(node):
80 if attr.startswith("_") or attr == "n" or attr == "s":
81 continue
82 to_return[attr] = get_value(getattr(node, attr))
83 to_return.pop("lineno", None)
84 to_return.pop("end_lineno", None)
85 to_return.pop("col_offset", None)
86 to_return.pop("end_col_offset", None)
87 return to_return
88
89
90def get_value(attr_value):

Callers 2

get_valueFunction · 0.85
ast_python.pyFile · 0.85

Calls 1

get_valueFunction · 0.85

Tested by

no test coverage detected