From de619b1754f9af8a09b171c5f842cb7f90775f05 Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Sun, 15 Dec 2019 20:10:40 +0100 Subject: [PATCH] pyln: Check to see if we have annotations on funcs before accessing We were indiscriminately accessing the `__annotations__` which could cause issues if the function had been wrapped by some functions such as `functools.partial`. This just checks that the access is safe before doing it. Suggested-by: jarret <@jarret> Signed-off-by: Christian Decker <@cdecker> --- contrib/pyln-client/pyln/client/plugin.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/contrib/pyln-client/pyln/client/plugin.py b/contrib/pyln-client/pyln/client/plugin.py index 3ca1da458..137da9c52 100644 --- a/contrib/pyln-client/pyln/client/plugin.py +++ b/contrib/pyln-client/pyln/client/plugin.py @@ -317,9 +317,10 @@ class Plugin(object): @staticmethod def _coerce_arguments(func, ba): args = OrderedDict() + annotations = func.__annotations__ if hasattr(func, "__annotations__") else {} for key, val in ba.arguments.items(): - annotation = func.__annotations__.get(key) - if annotation == Millisatoshi: + annotation = annotations.get(key, None) + if annotation is not None and annotation == Millisatoshi: args[key] = Millisatoshi(val) else: args[key] = val