forked from platypush/platypush
Use reflection to infer the arguments of a Python user procedure
This commit is contained in:
parent
0a1209fe6e
commit
27d4a20418
1 changed files with 8 additions and 1 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import inspect
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,7 +11,13 @@ class ProcedureEncoder(json.JSONEncoder):
|
||||||
if callable(o):
|
if callable(o):
|
||||||
return {
|
return {
|
||||||
'type': 'native_function',
|
'type': 'native_function',
|
||||||
'source': f'{o.__module__}.{o.__name__}',
|
'module': o.__module__,
|
||||||
|
'source': inspect.getsourcefile(o),
|
||||||
|
'args': [
|
||||||
|
name
|
||||||
|
for name, arg in inspect.signature(o).parameters.items()
|
||||||
|
if arg.kind != arg.VAR_KEYWORD
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
return super().default(o)
|
return super().default(o)
|
||||||
|
|
Loading…
Reference in a new issue