Closed GoogleCodeExporter closed 8 years ago
Thanks for the bug report and patch. r437 contains a fix very similar to yours,
but with a new line to separate all import statements from the next block of
variable definitions.
Original comment by Q.Neut...@gmail.com
on 28 Sep 2012 at 6:41
Thanks for fixing the problem. Unfortunately there is still an order problem.
All lines such as from X import Z aren't at the beginning.
In my opinion the following line of code has to be modified:
if (def.indexOf('import ') == 0) {
Suggestion:
if ( (def.indexOf('import ') = 0) || (def.indexOf('from ') == 0) ) {
best regards Marc
And i hope it's okay for you to suggest possible solutions :)
Original comment by borntob...@googlemail.com
on 28 Sep 2012 at 10:57
Ah, right. So I'll probably make it:
if (def.match(/^(from [\w.]+\s+)?import /))
Now the possible "from x import y" statements also brings back issue 74, so I
will be making further changes to collect all the potential imported names into
Blockly.Python.RESERVED_WORDS_.
Original comment by Q.Neut...@gmail.com
on 28 Sep 2012 at 8:07
Updated fix: if (fix: def.match(/^(from\s+\S+\s+)?import\s+\S+/)) { .
Regarding name collisions with variables, we determined that it's cumbersome to
collect all import libraries' names into Blockly.Python.RESERVED_WORDS_ at
runtime.
Hence, if you build any block that requires "import x" or "from x import y",
remember to add the names to RESERVED_WORDS_, like:
if (!Blockly.Python.RESERVED_WORDS_) {
Blockly.Python.RESERVED_WORDS_ = '';
}
Blockly.Python.RESERVED_WORDS_ += 'math,random,'; //or your imported libraries,
note the trailing comma.
Original comment by Q.Neut...@gmail.com
on 29 Sep 2012 at 9:35
Original issue reported on code.google.com by
borntob...@googlemail.com
on 27 Sep 2012 at 2:44