Skip to content

Commit 51ae95d

Browse files
committed
Fix needing annotations
1 parent 6ed4db0 commit 51ae95d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/editor/extended_python_generator.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export class OpModeDetails {
3131

3232
if (this.enabled){
3333
code += '@' + this.type + "\n";
34+
3435
if (this.name){
3536
code += '@name("' + this.name + '")\n';
3637
}
@@ -40,6 +41,20 @@ export class OpModeDetails {
4041
}
4142
return code;
4243
}
44+
imports() : string{
45+
let code = '';
46+
if (this.enabled){
47+
code += 'from blocks_base_classes import ' + this.type + '\n';
48+
if (this.name){
49+
code += 'from blocks_base_classes import name\n';
50+
}
51+
if (this.group){
52+
code += 'from blocks_base_classes import group\n';
53+
}
54+
}
55+
56+
return code;
57+
}
4358
}
4459

4560
// Extends the python generator to collect some information about functions and
@@ -181,6 +196,12 @@ export class ExtendedPythonGenerator extends PythonGenerator {
181196
const className = this.context.getClassName();
182197
const classParent = this.context.getClassParent();
183198
const annotations = this.details?.annotations();
199+
const import_annotations = this.details?.imports();
200+
201+
if(import_annotations){
202+
this.definitions_['import_annotations'] = import_annotations;
203+
}
204+
184205
this.addImport(classParent);
185206

186207
const classDef = 'class ' + className + '(' + classParent + '):\n';

0 commit comments

Comments
 (0)