microsoft / microsoft/pxt-microbit
Python can't handle negative key initialization
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 804
- Forks
- 721
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 2
Description
Describe the bug
Instantiating a dictionary with negative constants gives a parsing error in editor.
To Reproduce
x = -1
a = {1: 1}
b = {x: 1}
c = {-1: 1} # Error: ", expected"
d = {1: -1}
All initializations, except c work.
Desktop (please complete the following information):
- OS: Linux
- Browser: Mozilla Firefox 84.0.2
Additional context
Happens on branch master and on https://makecode.microbit.org
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
Reproduce the examples in the MakeCode editor on the master branch, using the linked micro:bit site if useful, and compare the accepted initializations with c = {-1: 1}. Trace the editor's Python parsing path for dictionary keys; done means negative constant keys parse without an error while the other examples remain valid.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, typescript
- Domain
- frontend, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100