@@ -31,6 +31,8 @@ import * as commonStorage from '../storage/common_storage';
31
31
export class ExtendedPythonGenerator extends PythonGenerator {
32
32
private currentModule : commonStorage . Module | null = null ;
33
33
private mapWorkspaceIdToExportedBlocks : { [ key : string ] : Block [ ] } = Object . create ( null ) ;
34
+ protected methods_ : { [ key : string ] : string } = Object . create ( null ) ;
35
+
34
36
35
37
constructor ( ) {
36
38
super ( 'Python' ) ;
@@ -159,7 +161,7 @@ export class ExtendedPythonGenerator extends PythonGenerator {
159
161
this . definitions_ [ 'import_' + importModule ] = 'import ' + importModule ;
160
162
}
161
163
addMethod ( methodName : string , code : string ) : void {
162
- this . definitions_ [ '%' + methodName ] = code ;
164
+ this . methods_ [ methodName ] = code ;
163
165
}
164
166
165
167
classParentFromModuleType ( moduleType : string ) : string {
@@ -189,19 +191,24 @@ export class ExtendedPythonGenerator extends PythonGenerator {
189
191
// Convert the definitions dictionary into a list.
190
192
const imports = [ ] ;
191
193
const definitions = [ ] ;
192
- const methods = [ ] ;
194
+
193
195
for ( let name in this . definitions_ ) {
194
196
const def = this . definitions_ [ name ] ;
195
197
if ( def . match ( / ^ ( f r o m \s + \S + \s + ) ? i m p o r t \s + \S + / ) ) {
196
198
imports . push ( def ) ;
197
- } else if ( name . match ( / ^ % .* / ) ) {
198
- methods . push ( def ) ;
199
199
} else {
200
200
definitions . push ( def ) ;
201
201
}
202
202
}
203
+ const methods = [ ] ;
204
+ for ( let name in this . methods_ ) {
205
+ methods . push ( this . methods_ [ name ] )
206
+ }
207
+
203
208
this . definitions_ = Object . create ( null ) ;
204
209
this . functionNames_ = Object . create ( null ) ;
210
+ this . methods_ = Object . create ( null ) ;
211
+
205
212
this . isInitialized = false ;
206
213
207
214
let class_def = "class " + className + "(" + classParent + "):\n" ;
0 commit comments