microsoft / microsoft/pxt-microbit

Switching from code blocks to python adds unnecessary code

Open
#4,423 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

decompiler P2 python
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:

  1. Paste the following code into the Python editor:

x = 0
basic.show_string(str(x))

  1. Switch to the code block view. (The code is converted fine)

image

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

image

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.