lsendel / blockly

Automatically exported from code.google.com/p/blockly
0 stars 0 forks source link

Python imports may generate name collisions #74

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. load the attached XML;
2. generate the corresponding Python code;
3. execute the generated code.

What is the expected output? What do you see instead?

The Python code generated looks like this:

  random = None
  import random
  random = random.random()
  print random
  random = random.random()
  print random

Which, when executed, leads to an obvious error:

  0.765087255685
  Traceback (most recent call last):
    File "/tmp/a", line 6, in <module>
      random = random.random()
  AttributeError: 'float' object has no attribute 'random'

Original issue reported on code.google.com by corbelli...@gmail.com on 17 Sep 2012 at 2:26

Attachments:

GoogleCodeExporter commented 8 years ago
Here is a patch for this issue. I've chosen to make the 
Blockly.*.RESERVED_WORDS_ variables "expansible". This also lets third-party 
generators to reserve names for import.

Original comment by corbelli...@gmail.com on 17 Sep 2012 at 2:31

Attachments:

GoogleCodeExporter commented 8 years ago

Original comment by neil.fra...@gmail.com on 17 Sep 2012 at 3:01

GoogleCodeExporter commented 8 years ago
Tricky bug, well-thought out patch. Thanks! 

Original comment by Q.Neut...@gmail.com on 21 Sep 2012 at 1:53