Skip to content

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

@berryde

Description

@berryde

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions