Skip to content

Commit 0f3a9bb

Browse files
committed
Where component methods are called, generate self.robot.<component name> instead of self.<component name>
Don't generate self.<component name> = robot.<component name> in the __init__ methods.
1 parent 9c8e04e commit 0f3a9bb

File tree

2 files changed

+1
-28
lines changed

2 files changed

+1
-28
lines changed

src/blocks/mrc_call_python_function.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,11 +421,10 @@ export const pythonFromBlock = function(
421421
}
422422
case FunctionKind.INSTANCE_COMPONENT: {
423423
const componentName = callPythonFunctionBlock.getComponentName();
424-
const varName = generator.componentNameToVarName(componentName);
425424
const functionName = callPythonFunctionBlock.mrcActualFunctionName
426425
? callPythonFunctionBlock.mrcActualFunctionName
427426
: block.getFieldValue(pythonUtils.FIELD_FUNCTION_NAME);
428-
code = 'self.' + varName + '.' + functionName;
427+
code = 'self.robot.' + componentName + '.' + functionName;
429428
break;
430429
}
431430
default:

src/editor/extended_python_generator.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export class ExtendedPythonGenerator extends PythonGenerator {
3434
private context: GeneratorContext | null = null;
3535

3636
private classMethods: {[key: string]: string} = Object.create(null);
37-
private mapComponentNameToVarName: {[key: string]: string} = Object.create(null);
3837

3938
constructor() {
4039
super('Python');
@@ -55,18 +54,6 @@ export class ExtendedPythonGenerator extends PythonGenerator {
5554
);
5655
}
5756
this.definitions_['variables'] = defvars.join('\n');
58-
59-
// Collect the components used in all mrc_call_python_function blocks.
60-
workspace.getBlocksByType('mrc_call_python_function', false).forEach((block) => {
61-
const callPythonFunctionBlock = block as CallPythonFunctionBlock;
62-
const componentName = callPythonFunctionBlock.getComponentName();
63-
if (componentName) {
64-
if (!(componentName in this.mapComponentNameToVarName)) {
65-
const varName = this.nameDB_!.getDistinctName(componentName, 'VARIABLE');
66-
this.mapComponentNameToVarName[componentName] = varName;
67-
}
68-
}
69-
});
7057
}
7158

7259
/*
@@ -80,10 +67,6 @@ export class ExtendedPythonGenerator extends PythonGenerator {
8067
variableDefinitions += this.INDENT + "self.mechanisms = []\n";
8168
}
8269

83-
Object.entries(this.mapComponentNameToVarName).forEach(([componentName, varName]) => {
84-
variableDefinitions += this.INDENT + 'self.' + varName + ' = robot.' + componentName + '\n';
85-
});
86-
8770
return variableDefinitions;
8871
}
8972
getVariableName(nameOrId: string): string {
@@ -120,13 +103,6 @@ export class ExtendedPythonGenerator extends PythonGenerator {
120103
this.classMethods[methodName] = code;
121104
}
122105

123-
/**
124-
* Get the variable name to use for a component.
125-
*/
126-
componentNameToVarName(componentName: string): string {
127-
return this.mapComponentNameToVarName[componentName];
128-
}
129-
130106
finish(code: string): string {
131107
if (this.context && this.workspace) {
132108
const className = this.context.getClassName();
@@ -143,8 +119,6 @@ export class ExtendedPythonGenerator extends PythonGenerator {
143119
this.context.setExportedBlocks(this.produceExportedBlocks(this.workspace));
144120
}
145121

146-
this.mapComponentNameToVarName = Object.create(null);
147-
148122
return super.finish(code);
149123
}
150124

0 commit comments

Comments
 (0)