@@ -331,6 +331,8 @@ ClassMethod GetFunctionInfo(function As %String = "", Output defined As %Boolean
331
331
quit :function =" " $$$ERROR($$$GeneralError, " Variable argument should be set" )
332
332
set sc = ..GetVariableInfo (function , , .defined , .type , .length )
333
333
quit :$$$ISERR(sc ) sc
334
+ quit :'defined $$$ERROR($$$GeneralError, " Function is not defined: " _ function )
335
+ quit :type =" type" ..GetFunctionInfo (function _ " .__init__" , .defined , .type , .docs , .signature , .arguments ) // for classes get constructor
334
336
quit :((type '=" function" ) && (type '=" method" ) && (type '=" builtin_function_or_method" ) && (type '=" method_descriptor" )) $$$ERROR($$$FormatText(" %1 is not a function/method, but a %2" , function , type ))
335
337
336
338
if defined {
@@ -369,21 +371,22 @@ ClassMethod GetFunctionInfo(function As %String = "", Output defined As %Boolean
369
371
/// Call arbitrary method or function.
370
372
/// **kwargs can't be passed using this method. Use ExecuteFunction instead if you need to pass **kwargs.
371
373
/// function - name of function to invoke. Can be nested, i.e. `random.randint`
374
+ /// variable - if provided, result of function execution would be set into this python variable
372
375
/// serialization - how to serialize result
373
376
/// result - write result into this variable
374
377
/// arguments - arguments as expected with triple dot syntax
375
378
/// set sc = ##class(isc.py.Main).ExecuteFunctionArgs()
376
- ClassMethod ExecuteFunctionArgs (function As %String , serialization As %Integer = {##class (isc.py.Callout ).#SerializationStr}, Output result As %String , arguments ... As %String ) As %Status
379
+ ClassMethod ExecuteFunctionArgs (function As %String , variable As %String = " zzzresult " , serialization As %Integer = {##class (isc.py.Callout ).#SerializationStr}, Output result As %String , arguments ... As %String ) As %Status
377
380
{
378
381
// We have no arguments
379
- quit :'$d (arguments ) ..ExecuteFunction (function , , , serialization , .result )
382
+ quit :'$d (arguments ) ..ExecuteFunction (function , , ,variable , serialization , .result )
380
383
381
384
#dim sc As %Status = $$$OK
382
385
kill defined , type
383
386
384
387
set sc = ..GetFunctionInfo (function , .defined , .type , , .signature , .funcArguments )
385
388
quit :$$$ISERR(sc ) sc
386
-
389
+
387
390
set positionalArguments = " "
388
391
set keywordArguments = " "
389
392
@@ -399,8 +402,8 @@ ClassMethod ExecuteFunctionArgs(function As %String, serialization As %Integer =
399
402
#dim kwonlyargs As %DynamicArray = funcArgObj .%Get (4 )
400
403
#dim kwonlydefaults As %DynamicArray = funcArgObj .%Get (5 )
401
404
402
- // Remove self argument if it's a method.
403
- do :type [" method" args .%Remove (0 )
405
+ // Remove self argument if it's a method or a constructor function
406
+ do :(( type [" method" ) || ( $isObject ( args ) && ( args . %Get ( 0 )= " self " ))) args .%Remove (0 )
404
407
405
408
#dim posCount As %Integer = $case ($isObject (args ), $$$YES: args .%Size (), :0 )
406
409
#dim kwCount As %Integer = $case ($isObject (kwonlyargs ), $$$YES: kwonlyargs .%Size (), :0 )
@@ -427,7 +430,7 @@ ClassMethod ExecuteFunctionArgs(function As %String, serialization As %Integer =
427
430
}
428
431
429
432
//zw kwCount,positionalCount,keywordCount,arguments,size,signature,funcArguments,positionalArguments, keywordArguments
430
- set sc = ..ExecuteFunction (function , positionalArguments , keywordArguments , serialization , .result )
433
+ set sc = ..ExecuteFunction (function , positionalArguments , keywordArguments , variable , serialization , .result )
431
434
432
435
quit sc
433
436
}
@@ -436,18 +439,19 @@ ClassMethod ExecuteFunctionArgs(function As %String, serialization As %Integer =
436
439
/// function - name of function to invoke. Can be nested, i.e. `random.randint`
437
440
/// positionalArguments - $lb(val1, val2, ..., valN) or any %Collection.AbstractIterator class or Dynamic array
438
441
/// keywordArguments - $lb($lb(name1, val1), $lb(name2, val2), ..., $lb(nameN, valN)) or any %Collection.AbstractArray class or flat Dynamic object
439
- /// serialization -how to serialize result
442
+ /// variable - if provided, result of function execution would be set into this python variable
443
+ /// serialization - how to serialize result
440
444
/// result - write result into this variable
441
445
/// set sc = ##class(isc.py.Main).ExecuteFunction()
442
- ClassMethod ExecuteFunction (function As %String , positionalArguments As %List = " " , keywordArguments As %List = " " , serialization As %Integer = {##class (isc.py.Callout ).#SerializationStr}, Output result As %String ) As %Status
446
+ ClassMethod ExecuteFunction (function As %String , positionalArguments As %List = " " , keywordArguments As %List = " " , variable As %String = " zzzresult " , serialization As %Integer = {##class (isc.py.Callout ).#SerializationStr}, Output result As %String ) As %Status
443
447
{
444
448
#dim sc As %Status = $$$OK
445
449
kill defined , type
446
450
447
451
set sc = ..GetFunctionInfo (function , .defined , .type , , .signature , .arguments )
448
452
quit :$$$ISERR(sc ) sc
449
-
450
- set code = " zzzresult =" _ function _ " ("
453
+
454
+ set code = variable _ " =" _ function _ " ("
451
455
if (positionalArguments '=" " ) {
452
456
if (($listvalid (positionalArguments )) && ($ll (positionalArguments )>0 )) {
453
457
set code = code _ $lts (positionalArguments )
@@ -492,11 +496,11 @@ ClassMethod ExecuteFunction(function As %String, positionalArguments As %List =
492
496
493
497
set code = code _ " )"
494
498
495
- zw code
496
- set sc = ..SimpleString (code , " zzzresult " , serialization , .result )
499
+ // zw code
500
+ set sc = ..SimpleString (code , variable , serialization , .result )
497
501
quit :$$$ISERR(sc ) sc
498
502
499
- set sc = ..SimpleString (" del zzzresult" )
503
+ set : variable = " zzzresult " sc = ..SimpleString (" del zzzresult" )
500
504
501
505
quit sc
502
506
}
0 commit comments