Skip to content

Commit 54ac8e1

Browse files
committed
Updated block type mrc_call_python_function to support calling an instance function within the same class.
1 parent d2bc58f commit 54ac8e1

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/blocks/mrc_call_python_function.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const FUNCTION_KIND_MODULE = 'module';
3737
const FUNCTION_KIND_STATIC = 'static';
3838
const FUNCTION_KIND_CONSTRUCTOR = 'constructor';
3939
const FUNCTION_KIND_INSTANCE = 'instance';
40+
const FUNCTION_KIND_INSTANCE_WITHIN = 'instance_within';
4041

4142
const RETURN_TYPE_NONE = 'None';
4243

@@ -127,6 +128,11 @@ const CALL_PYTHON_FUNCTION = {
127128
tooltip = 'Calls the function ' + className + '.' + functionName + '.';
128129
break;
129130
}
131+
case FUNCTION_KIND_INSTANCE_WITHIN: {
132+
const functionName = this.getFieldValue(pythonUtils.FIELD_FUNCTION_NAME);
133+
tooltip = 'Calls the method ' + functionName + '.';
134+
break;
135+
}
130136
default:
131137
throw new Error('mrcVarKind must be "module", "static", "constructor", or "instance".')
132138
}
@@ -238,6 +244,11 @@ const CALL_PYTHON_FUNCTION = {
238244
.appendField('.')
239245
.appendField(createFieldNonEditableText(''), pythonUtils.FIELD_FUNCTION_NAME);
240246
break;
247+
case FUNCTION_KIND_INSTANCE_WITHIN:
248+
this.appendDummyInput()
249+
.appendField('call')
250+
.appendField(createFieldNonEditableText(''), pythonUtils.FIELD_FUNCTION_NAME);
251+
break;
241252
default:
242253
throw new Error('mrcVarKind must be "module", "static", "constructor", or "instance".')
243254
}
@@ -301,6 +312,14 @@ export const pythonFromBlock = function(
301312
argStartIndex = 1; // Skip the self argument.
302313
break;
303314
}
315+
case FUNCTION_KIND_INSTANCE_WITHIN: {
316+
const callPythonFunctionBlock = block as CallPythonFunctionBlock;
317+
const functionName = (callPythonFunctionBlock.mrcActualFunctionName)
318+
? callPythonFunctionBlock.mrcActualFunctionName
319+
: block.getFieldValue(pythonUtils.FIELD_FUNCTION_NAME);
320+
code = 'self.' + functionName;
321+
break;
322+
}
304323
}
305324
code += '(' + generateCodeForArguments(callPythonFunctionBlock, generator, argStartIndex) + ')';
306325
if (block.outputConnection) {

0 commit comments

Comments
 (0)