Skip to content

Commit

Permalink
Updated _inspect() method in platform/vip/agent/subsystems/rpc.py for…
Browse files Browse the repository at this point in the history
… changes to inspect module in Python 3 plus some enhancements to output.
  • Loading branch information
davidraker committed Jun 24, 2020
1 parent 10e75a7 commit 5659823
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions volttron/platform/vip/agent/subsystems/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down

0 comments on commit 5659823

Please sign in to comment.