From 5659823aa4338c501b18776d3cb7027a9c734f9f Mon Sep 17 00:00:00 2001 From: "David M. Raker" Date: Tue, 23 Jun 2020 14:34:06 -0400 Subject: [PATCH] Updated _inspect() method in platform/vip/agent/subsystems/rpc.py for changes to inspect module in Python 3 plus some enhancements to output. --- volttron/platform/vip/agent/subsystems/rpc.py | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/volttron/platform/vip/agent/subsystems/rpc.py b/volttron/platform/vip/agent/subsystems/rpc.py index 7945f2dc4c..441b59b745 100644 --- a/volttron/platform/vip/agent/subsystems/rpc.py +++ b/volttron/platform/vip/agent/subsystems/rpc.py @@ -168,11 +168,18 @@ def method(self, request, ident, name, args, kwargs, del local.request del local.batch - def _inspect(self, method): - params = inspect.getargspec(method) - if hasattr(method, 'im_self'): - params.args.pop(0) - response = {'params': params} + @staticmethod + def _inspect(method): + response = {'params': {}} + signature = inspect.signature(method) + for p in signature.parameters.values(): + response['params'][p.name] = { + 'kind': p.kind.description + } + if p.default is not inspect.Parameter.empty: + response['params'][p.name]['default'] = p.default + if p.annotation is not inspect.Parameter.empty: + response['params'][p.name]['annotation'] = p.annotation doc = inspect.getdoc(method) if doc: response['doc'] = doc @@ -181,15 +188,15 @@ def _inspect(self, method): cut = len(os.path.commonprefix([_ROOT_PACKAGE_PATH, source])) source = source[cut:] lineno = inspect.getsourcelines(method)[1] - except IOError: + except Exception: pass else: - response['source'] = source, lineno - try: - # pylint: disable=protected-access - response['return'] = method._returns - except AttributeError: - pass + response['source'] = { + 'file': source, + 'line_number': lineno + } + if signature.return_annotation is not inspect.Signature.empty: + response['return'] = signature.return_annotation return response