Skip to content

Commit

Permalink
Update to work with Python 3's ast module
Browse files Browse the repository at this point in the history
  • Loading branch information
benmwebb committed Jun 5, 2024
1 parent fa90a00 commit d8eb84a
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions tools/build/doxygen_filter_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,23 @@ def format_item(key, val):
+ " " + format_value(val.right)
elif isinstance(val, ast.UnaryOp):
return format_value(val.op) + format_value(val.operand)
elif isinstance(val, ast.Starred):
return "*" + format_value(val.value)
elif has_constant and isinstance(val, ast.Constant):
return repr(val.value)
elif not has_constant and isinstance(val, ast.Num):
return str(val.n)
elif not has_constant and isinstance(val, ast.Str):
return repr(val.s)
elif isinstance(val, ast.Call):
args = [format_value(x) for x in val.args] + \
["%s=%s" % (x.arg, format_value(x.value)) for x in val.keywords]
if val.starargs:
args.append('*' + val.starargs.id)
if val.kwargs:
args.append('**' + val.kwargs.id)
args = [format_value(x)
for x in val.args if not isinstance(x, ast.Starred)] + \
["%s=%s" % (x.arg, format_value(x.value))
for x in val.keywords if x.arg is not None] + \
[format_value(x)
for x in val.args if isinstance(x, ast.Starred)] + \
["**" + format_value(x.value)
for x in val.keywords if x.arg is None]
return format_value(val.func) + '(' + ", ".join(args) + ')'
raise ValueError("Do not know how to format %s while running %s"
% (str(val), str(sys.argv)))
Expand Down Expand Up @@ -119,9 +123,9 @@ def format_arg(arg):
args = [format_arg(x) for x in args]
sig += ", ".join(args)
if m.args.vararg:
sig += ", *" + m.args.vararg
sig += ", *" + m.args.vararg.arg
if m.args.kwarg:
sig += ", **" + m.args.kwarg
sig += ", **" + m.args.kwarg.arg
return sig + '):'


Expand Down

0 comments on commit d8eb84a

Please sign in to comment.