microsoft / microsoft/pxt-microbit

Python can't handle negative key initialization

Open
#3,844 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.