microsoft / microsoft/monaco-editor

[Bug] Python syntax highlighting does not support underscores in numeric literals

Open
#4,745 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug confirmed editor-highlight
Dominant language
JavaScript
Stars
46.8k
Forks
4.1k
Avg merge
17h 58m
Merged PRs (30d)
1

Description

Reproducible in vscode.dev or in VS Code Desktop?
  • Not reproducible in vscode.dev or VS Code Desktop
Reproducible in the monaco editor playground?
Monaco Editor Playground Link

https://microsoft.github.io/monaco-editor/playground.html?source=v0.52.0#XQAAAAKnAQAAAAAAAABBqQkHQ5NjdMjwa-jY7SIQ9S7DNlzs5W-mwj0fe1ZCDRFc9ws9XQE0SJE1jc2VKxhaLFIw9vEWSxW3yscwzyNqXz8HGcRM7llq60Xf2dFVQaKGLkRsRu_z2ZE0NWgzCg62BuIVYtanb18eMNBNJsjVjyiYVHIbaAyf-nA4BerZWoQmUlMw-vMw3l1KEgsDwXUkFxkTWBpnTf4yO_qcZeejWbg2ck2NXeVHUfoPmtoeVUkxzH0S2hd6vksr2ua8lr3VCFo3Yjoss8fLIqw0VMhVOL7PYm9fvVPtU3Kp0tpUzhjV_E85CtmMO5xILERoMbp6yNzxyCG8Ko0RhRkKQXkyVZetsnXkCKUU3yPbfu2U53W0MZbSao9Fwac1gbpMNNwYku2aST_QKM_P5J7WkQlWVUDY5ErzL3oG58Eu_Jz-gOHa2geOwo_Mop__-LpYMQ

Monaco Editor Playground Code
const value = /* set from `myEditor.getModel()`: */ `# '100_000' should be formatted as a single value per https://peps.python.org/pep-0515/
numeric_literal_example = 100_000`;

// Hover on each property to see its docs!
const myEditor = monaco.editor.create(document.getElementById("container"), {
	value,
	language: "python",
	automaticLayout: true,
});
Reproduction Steps

Open the playground link. Verify that 100_000 is formatted inconsistently.

Actual (Problematic) Behavior

Numeric literals with underscores are not highlighted as a single value by the syntax highlighter.

Image

Expected Behavior

Numeric literals with underscores should be highlighted as a single value, as is done in VS Code.

Image

Additional Context

Numeric literals with underscores were proposed in https://peps.python.org/pep-0515/ and have been supported since Python 3.6.

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 with the linked Monaco Editor Playground and reproduce the Python example containing 100_000. Locate the Python syntax-highlighting definition used by Monaco and compare its behavior with the expected VS Code highlighting. Done means the numeric literal is highlighted as one value while existing Python highlighting remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
developer-experience
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.