microsoft / microsoft/pxt-microbit
Blocks programs w/ variables usually convert to Python programs with "global" keyword everywhere
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 804
- Forks
- 721
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 2
Description
Because all variables in blocks are global and we preserve this when converting to TS and then to PY, we end up with a lot of "global" keywords all over the place when converting to Python.
I think this is going to be especially problematic for new users learning Python since the "global" and "nonlocal" keywords are some of the more confusing aspects of the language.
Most cases these global variables should really be converted to local variables when switching to TS or PY. This could be done fairly easily if we did a liveness analysis to determine when it's safe to make variables local.
Here's a simple blocks program that is over complicated when switching to Python:

I think this will be especially problematic for Arcade since there are more variables used there.
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
The issue does not name any files, tests, or entry points. Start by locating the Blocks-to-TypeScript-to-Python conversion path and determine how variable scope is currently preserved; done should mean generated Python avoids unnecessary global declarations while retaining program behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, typescript
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100