Skip to content

(Python) Part of an identifier is highlighted as a keyword #3378

@wjandrea

Description

@wjandrea

Describe the issue

Syntax highlighting changes halfway through a Python identifier _undef to look like the def keyword.

Which language seems to have the issue?

python

Are you using highlight or highlightAuto?
I don't know what that means. I assume it's about how highlight.js is deployed, but I'm an end user, not a Stack Exchange dev.

Sample Code to Reproduce

foo = _undef
bar

https://jsfiddle.net/td6a2fhg/

Screenshot of fiddle:
screenshot of fiddle showing the issue

Expected behavior

GitHub gets it right.

All other syntax highlighters I checked don't seem to highlight anything.

Additional context

  • This issue started with 11.0.0 and does not exist in 10.7.3
  • I noticed the problem "in the wild" on this Stack Overflow answer.
  • The HTML output from the fiddle:
    <code class="python lang-python hljs language-python">foo = _un<span class="hljs-keyword">def</span>
    <span class="hljs-title function_">bar</span>
    </code>
  • The issue doesn't occur when the identifier is followed by a different token, like a literal:
    foo = _undef
    []

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions