Skip to content

Commit 986f5d4

Browse files
authored
Parse self.<var> outputs correctly. Closes #1815 (#1890)
1 parent f7e3e2c commit 986f5d4

3 files changed

Lines changed: 23 additions & 4 deletions

File tree

src/common/OperationCode.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,10 +408,14 @@ var isNodeJs = typeof module === 'object' && module.exports;
408408
schema.methods[name].outputs = retVals
409409
.filter(node => !!node)
410410
.map((arg, index) => {
411-
var isNameNode = OperationCode.isNodeType(arg, 'Name');
412-
var name = isNameNode ? arg.id.v : 'result';
413-
if (!isNameNode && index > 0) {
414-
name += '_' + index;
411+
let name = index > 0 ? `result_${index}` : 'result';
412+
const isNameNode = OperationCode.isNodeType(arg, 'Name');
413+
const isSelfAttr = OperationCode.isNodeType(arg, 'Attribute') &&
414+
arg.value.id.v === 'self';
415+
if (isNameNode) {
416+
name = arg.id.v;
417+
} else if (isSelfAttr) {
418+
name = arg.attr.v;
415419
}
416420

417421
var value = OperationCode.isNodeType(arg, 'Num') ? arg.n.v : name;

test/unit/common/OperationCode.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,13 @@ describe('OperationCode', function() {
226226
assert.deepEqual(operation.getOutputs().map(output => output.name), names);
227227
});
228228

229+
it('should parse the output name when returning attr', async function() {
230+
const code = testCase('op-output-name.py');
231+
const operation = new OperationCode(code);
232+
const names = ['myOutput'];
233+
assert.deepEqual(operation.getOutputs().map(output => output.name), names);
234+
});
235+
229236
it.skip('should parse the output types', function() {
230237
const types = ['str', 'int'];
231238
assert.deepEqual(operation.getOutputs().map(output => output.type), types);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from operations import Operation
2+
from typing import Tuple
3+
4+
class ExampleOperation(Operation):
5+
6+
def execute(hello, world, count):
7+
self.myOutput = hello + world
8+
return self.myOutput

0 commit comments

Comments
 (0)