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: blacklight
GPG Key ID: D90FBA7F76362774
1 changed files with 8 additions and 1 deletions

View File

@ -1,3 +1,4 @@
import inspect
import json
@ -10,7 +11,13 @@ class ProcedureEncoder(json.JSONEncoder):
if callable(o):
return {
'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)