microsoft / microsoft/pxt-microbit
Switching from code blocks to python adds unnecessary code
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 804
- Forks
- 721
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 2
Description
Describe the bug
In the makecode.microbit.org editor: Converting python code to block code and back introduces unnecessary code.
To Reproduce
Steps to reproduce the behavior:
- Paste the following code into the Python editor:
x = 0
basic.show_string(str(x))
- Switch to the code block view. (The code is converted fine)

- Switch back to the Python code, note the added "" + before the x variable.

That's it, if you now add a newline to the python code and switch back to the block code you will have a new "join" Block.
Expected behavior
No empty string should be prepended to the code.
Screenshots
See above
micro:bit version (please complete the following information):
- Makecode Editor only (unrelated to any hardware)
Desktop (please complete the following information):
- OS: MacOS 12 (m1)
- Browser Chrome
- Version 95.0.4638.69 (Offizieller Build) (arm64)
Also reproducible on Safari 15.1
Additional context
This might be related to the JavaScript string conversion (using an empty string to force convert variables to strings). However this is unnecessary in Python.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in the MakeCode editor's Python-to-blocks and blocks-to-Python conversion path, reproducing the supplied x = 0 example in the Python editor. Confirm the round trip and newline behavior, then verify that no empty-string prefix or unnecessary join block is introduced.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100