File tree Expand file tree Collapse file tree 2 files changed +30
-2
lines changed
Expand file tree Collapse file tree 2 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -365,9 +365,9 @@ export const pythonFromBlock = function (
365365 branch = generator . INDENT + 'super.__init__(' + class_specific + ')\n' +
366366 generator . defineClassVariables ( ) + branch ;
367367 }
368- else if ( funcName == 'update' ) {
368+ else if ( generator . inBaseClassMethod ( blocklyName ) ) {
369369 // Special case for update, to also call the update method of the base class
370- branch = generator . INDENT + 'super.update ()\n' + branch ;
370+ branch = generator . INDENT + 'super.' + blocklyName + ' ()\n' + branch ;
371371 }
372372 if ( returnValue ) {
373373 returnValue = generator . INDENT + 'return ' + returnValue + '\n' ;
Original file line number Diff line number Diff line change @@ -212,6 +212,34 @@ export class ExtendedPythonGenerator extends PythonGenerator {
212212 }
213213 return ''
214214 }
215+
216+ /**
217+ * This returns the list of methods that are derived from so that mrc_class_method_def
218+ * knows whether to call super() or not.
219+ * @returns list of method names
220+ */
221+ getBaseClassMethods ( ) : string [ ] {
222+ let classParent = this . context ?. getClassParent ( ) ;
223+ if ( classParent == 'OpMode' ) {
224+ return [ 'start' , 'loop' , 'stop' ] ;
225+ }
226+ else if ( classParent == 'Mechanism' ) {
227+ return [ 'start' , 'update' , 'stop' ] ;
228+ }
229+ else if ( classParent == 'RobotBase' ) {
230+ return [ 'start' , 'update' , 'stop' ] ;
231+ }
232+ return [ ] ;
233+ }
234+
235+ /**
236+ * Returns true if the method is in the base class.
237+ * @param methodName the name of the method to check
238+ */
239+ inBaseClassMethod ( methodName : string ) : boolean {
240+ const baseMethods = this . getBaseClassMethods ( ) ;
241+ return baseMethods . includes ( methodName ) ;
242+ }
215243}
216244
217245export const extendedPythonGenerator = new ExtendedPythonGenerator ( ) ;
You can’t perform that action at this time.
0 commit comments