Browse Source

pylightning: Exception if we have unfulfilled positional arguments

This caused me to backtrack quite a bit, so this should help debugging
in the future.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
pylightning-async
Christian Decker 6 years ago
parent
commit
834df3180c
No known key found for this signature in database GPG Key ID: 1416D83DC4F0E86D
  1. 13
      contrib/pylightning/lightning/plugin.py

13
contrib/pylightning/lightning/plugin.py

@ -242,7 +242,7 @@ class Plugin(object):
arguments = OrderedDict()
for name, value in sig.parameters.items():
arguments[name] = inspect.Signature.empty
arguments[name] = inspect._empty
# Fill in any injected parameters
if 'plugin' in arguments:
@ -257,7 +257,7 @@ class Plugin(object):
else:
pos = 0
for k, v in arguments.items():
if v is not inspect.Signature.empty:
if v != inspect._empty:
continue
if pos < len(params):
# Apply positional args if we have them
@ -267,6 +267,15 @@ class Plugin(object):
arguments[k] = sig.parameters[k].default
pos += 1
missing = [k for k, v in arguments.items() if v == inspect._empty]
if missing:
raise ValueError("Missing positional arguments ({given} given, "
"expected {expected}): {missing}".format(
missing=", ".join(missing),
given=len(arguments) - len(missing),
expected=len(arguments)
))
ba = sig.bind(**arguments)
ba.apply_defaults()
return func(*ba.args, **ba.kwargs)

Loading…
Cancel
Save