Skip to content

Commit

Permalink
enh(python) treat self as a keyword (#4025)
Browse files Browse the repository at this point in the history
  • Loading branch information
lfalin committed Mar 23, 2024
1 parent e00aa26 commit 0d7061c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -21,6 +21,7 @@ Core Grammars:
- fix(csharp) add raw string highlighting for C# 11. [Tara][]
- fix(bash) fix # within token being detected as the start of a comment [Felix Uhl][]
- fix(python) fix `or` conflicts with string highlighting [Mohamed Ali][]
- enh(python) adds a scope to the `self` variable [Lee Falin][]
- enh(delphi) allow digits to be omitted for hex and binary literals [Jonah Jeleniewski][]
- enh(delphi) add support for digit separators [Jonah Jeleniewski][]
- enh(delphi) add support for character strings with non-decimal numerics [Jonah Jeleniewski][]
Expand Down
3 changes: 2 additions & 1 deletion src/languages/python.js
Expand Up @@ -373,7 +373,8 @@ export default function(hljs) {
NUMBER,
{
// very common convention
begin: /\bself\b/
scope: 'variable.language',
match: /\bself\b/
},
{
// eat "if" prior to string so that it won't accidentally be
Expand Down
6 changes: 6 additions & 0 deletions test/markup/python/class_self.expect.txt
@@ -0,0 +1,6 @@
<span class="hljs-keyword">class</span> <span class="hljs-title class_">SelfTest</span>:
<span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self</span>):
<span class="hljs-variable language_">self</span>.text = <span class="hljs-literal">True</span>

<span class="hljs-keyword">def</span> <span class="hljs-title function_">method</span>(<span class="hljs-params">self</span>):
<span class="hljs-keyword">pass</span>
6 changes: 6 additions & 0 deletions test/markup/python/class_self.txt
@@ -0,0 +1,6 @@
class SelfTest:
def __init__(self):
self.text = True

def method(self):
pass

0 comments on commit 0d7061c

Please sign in to comment.