Skip to content

Commit

Permalink
fix(bindgen): Fix Python tuple outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed Apr 28, 2023
1 parent a56b0b0 commit d70430f
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions src/bindgen/python.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,19 +223,6 @@ function functionModuleReturnType(interfaceJson) {
returnType = interfaceJsonTypeToPythonType.get(jsonOutputs[0].type)
}

if (jsonOutputs.length > 1) {
returnType += "Tuple["
jsonOutputs.forEach((value) => {
const pythonType = interfaceJsonTypeToPythonType.get(value.type)
returnType += `${pythonType}, `
})
returnType = returnType.substring(0, returnType.length - 2)
returnType += "]"
returnType += " )\n"
} else {
returnType = interfaceJsonTypeToPythonType.get(jsonOutputs[0].type)
}

return returnType
}

Expand Down Expand Up @@ -329,8 +316,8 @@ from itkwasm import (
interfaceJson.inputs.forEach((input) => {
if (interfaceJsonTypeToInterfaceType.has(input.type)) {
const interfaceType = interfaceJsonTypeToInterfaceType.get(input.type)
const name = interfaceType.includes('File') ? `str(${snakeCase(input.name)})` : inputCount.toString()
args += ` args.append('${name}')\n`
const name = interfaceType.includes('File') ? `str(${snakeCase(input.name)})` : `'${inputCount.toString()}'`
args += ` args.append(${name})\n`
inputCount++
} else {
const snake = snakeCase(input.name)
Expand Down Expand Up @@ -451,6 +438,7 @@ from itkwasm import (
const outputValue = `outputs[${index}]`
postOutput += ` ${toPythonType(value.type, outputValue)},\n`
})
postOutput += ' )\n'
} else {
const outputValue = "outputs[0]"
postOutput = ` result = ${toPythonType(jsonOutputs[0].type, outputValue)}\n`
Expand All @@ -471,9 +459,9 @@ ${pipelineInputs} ]
${args}
outputs = pipeline.run(args, pipeline_outputs, pipeline_inputs)
${postOutput}
del pipeline
${postOutput}
`
fs.writeFileSync(modulePath, moduleContent)
}
Expand Down

0 comments on commit d70430f

Please sign in to comment.