Use reflection to infer the arguments of a Python user procedure

This commit is contained in:
Fabio Manganiello 2023-05-17 17:17:59 +02:00
parent 0a1209fe6e
commit 27d4a20418
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774

View file

@ -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)