yuuchilyann / blockly

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

Compatibility with Python 3 #75

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
The Python code generated by Blockly is not compatible with Python 3. 
Specifically:

1. Blockly uses the 'print' statement;
2. Blockly uses the raw_input() function;
3. Division between integers returns different results in Python 2 or 3 (try 
for example 5 / 3).

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

GoogleCodeExporter commented 8 years ago
The attached patch solves the problems in the following ways:

1. The argument passed to print is parenthesized.
2. raw_input() is first called; if the call fails, input() is used instead.
3. We make sure that at least the dividend is a float.

The patch also fixes some minor bugs:

* Math.PI -> math.pi;
* Blockly.Python.math_random_int returns the correct value.

Original comment by corbelli...@gmail.com on 17 Sep 2012 at 3:03

Attachments:

GoogleCodeExporter commented 8 years ago
I'm going to claim that point 3 is not an issue since Blockly does not 
guarantee identical results in all languages.  To do otherwise would require 
every operator to be wrapped in a function call.  This would kill legibility of 
the generated code.  See the last point on this page:
http://code.google.com/p/blockly/wiki/Language

Assigning to our Python guru, Quynh.

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

GoogleCodeExporter commented 8 years ago
Good point, you are right. The problem of legibility also came to my 
mind while I was writing the fix. Here is the same patch without the 
integer division fix.

Original comment by corbelli...@gmail.com on 17 Sep 2012 at 3:28

GoogleCodeExporter commented 8 years ago
Andrea,
Thank you for finding the bugs and providing great patches! Patches for issue 
74 and issue 75 are now part of r419. You not only know JavaScript and Python 
well but seem to understand deeply how Blockly works, it would be great if you 
were a committer!

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