From 985fd7377b853548b8fc22cd8b7d5358548a773c Mon Sep 17 00:00:00 2001 From: whitequark Date: Fri, 1 Jun 2018 19:16:26 +0000 Subject: [PATCH] artiq_rpctool: use inspect.formatargspec instead of a NIH formatter. Fixes #1029. --- artiq/frontend/artiq_rpctool.py | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/artiq/frontend/artiq_rpctool.py b/artiq/frontend/artiq_rpctool.py index 74cb8890a..fb9844f29 100755 --- a/artiq/frontend/artiq_rpctool.py +++ b/artiq/frontend/artiq_rpctool.py @@ -6,6 +6,7 @@ import sys import traceback import numpy as np # Needed to use numpy in RPC call arguments on cmd line import pprint +import inspect from artiq.protocols.pc_rpc import AutoTarget, Client @@ -46,33 +47,7 @@ def list_methods(remote): print(doc["docstring"]) print() for name, (argspec, docstring) in sorted(doc["methods"].items()): - args = "" - for arg in argspec["args"]: - args += arg - if argspec["defaults"] is not None: - kword_index = len(argspec["defaults"]) - len(argspec["args"])\ - + argspec["args"].index(arg) - if kword_index >= 0: - if argspec["defaults"][kword_index] == Ellipsis: - args += "=..." - else: - args += "={}".format(argspec["defaults"][kword_index]) - if argspec["args"].index(arg) < len(argspec["args"]) - 1: - args += ", " - if argspec["varargs"] is not None: - args += ", *{}".format(argspec["varargs"]) - elif len(argspec["kwonlyargs"]) > 0: - args += ", *" - for kwonlyarg in argspec["kwonlyargs"]: - args += ", {}".format(kwonlyarg) - if kwonlyarg in argspec["kwonlydefaults"]: - if argspec["kwonlydefaults"][kwonlyarg] == Ellipsis: - args += "=..." - else: - args += "={}".format(argspec["kwonlydefaults"][kwonlyarg]) - if argspec["varkw"] is not None: - args += ", **{}".format(argspec["varkw"]) - print("{}({})".format(name, args)) + print(name + inspect.formatargspec(**argspec)) if docstring is not None: print(textwrap.indent(docstring, " ")) print()