PythonEditor
PythonEditor copied to clipboard
Blocks: "change <variable> by" block causes import error
The 'change variable by' block causes the following import statement to be emitted:
from numbers import Number
Which in turn causes an ImportError on the device.
It also generates rather confusing code:
count = (count if isinstance(count, Number) else 0) + -1
See the following program as an example of failure:

Ugh... that's horrible. :scream:
I know how to fix it but it'll mean faffing about with the XML menu and creating a new block. It's probably also something that should be addressed in the "upstream" PyBlocks project run by the esteemed @carlosperate.
Yes, that is one of the disadvantages of blockly trying to generate "always valid" code, it sometimes end ups generating verbose and ugly code as well. One of the next things I wanted to do is extract the default blocks (for reasons of compability with blockly and scratch-blocks) and extend them or make them a bit more pythonic. Taking in consideration we are going to find a few things like this I think the best way forward would be to overwrite the "change by" block generator in the microbit instance.