diff --git a/CHANGES.md b/CHANGES.md
index 4b7c3021fd..f84b617f3f 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -25,6 +25,7 @@ Core Grammars:
- enh(json) add json5 support [Kerry Shetline][]
- fix(css) `unicode-range` parsing, issue #4253 [Kerry Shetline][]
- fix(csharp) Support digit separators [te-ing][]
+- enh(python) add support for methods and properties [fibbo][]
Documentation:
@@ -53,6 +54,7 @@ CONTRIBUTORS
[Thomas Gorissen]: https://github.com/serrynaimo
[te-ing]: https://github.com/te-ing
[Anthony Martin]: https://github.com/anthony-c-martin
+[fibbo]: https://github.com/fibbo
## Version 11.11.1
diff --git a/src/languages/python.js b/src/languages/python.js
index 2604889790..3e3b53785c 100644
--- a/src/languages/python.js
+++ b/src/languages/python.js
@@ -383,6 +383,39 @@ export default function(hljs) {
relevance: 0
},
{ match: /\bor\b/, scope: "keyword" },
+ // Method calls with parentheses
+ {
+ match: [
+ /\./,
+ IDENT_RE,
+ /(?=\s*\()/
+ ],
+ scope: {
+ 2: "title.function.method"
+ }
+ },
+ // Chained method calls
+ {
+ match: [
+ /\./,
+ IDENT_RE,
+ /(?=\s*\.\s*\w)/
+ ],
+ scope: {
+ 2: "title.function.method"
+ }
+ },
+ {
+ match: [
+ /(?>>> print(v)
foo = 42
->>> print(repr(v).rstrip('"'))
+>>> print(repr(v).rstrip('"'))
"foo = 42
->>> print(repr(v).lstrip('"'))
+>>> print(repr(v).lstrip('"'))
foo = 42"
>>> """
diff --git a/test/markup/python/class_self.expect.txt b/test/markup/python/class_self.expect.txt
index db39ede4a9..08ceac87f0 100644
--- a/test/markup/python/class_self.expect.txt
+++ b/test/markup/python/class_self.expect.txt
@@ -1,6 +1,6 @@
class SelfTest:
def __init__(self):
- self.text = True
+ self.text = True
def method(self):
pass
diff --git a/test/markup/python/function-header-comments.expect.txt b/test/markup/python/function-header-comments.expect.txt
index 35041289d8..9215af8fa2 100644
--- a/test/markup/python/function-header-comments.expect.txt
+++ b/test/markup/python/function-header-comments.expect.txt
@@ -4,7 +4,7 @@
pass
-class Foo(collections.namedtuple('Test'), (
+class Foo(collections.namedtuple('Test'), (
'name',
)):
pass
diff --git a/test/markup/python/keywords.expect.txt b/test/markup/python/keywords.expect.txt
index f2227af2f5..b5bb7fb80f 100644
--- a/test/markup/python/keywords.expect.txt
+++ b/test/markup/python/keywords.expect.txt
@@ -1,14 +1,18 @@
+from base.derive import test
+import base.test
+
class Shorty(dict):
def len(self):
return NotImplemented
x = Shorty()
+x.len()
len(x)
if __debug__:
sys = __import__('sys')
-for _ in sys.path:
+for _ in sys.path:
print(_)
exec(123)
diff --git a/test/markup/python/keywords.txt b/test/markup/python/keywords.txt
index 30e3d0a180..8b32aec233 100644
--- a/test/markup/python/keywords.txt
+++ b/test/markup/python/keywords.txt
@@ -1,8 +1,12 @@
+from base.derive import test
+import base.test
+
class Shorty(dict):
def len(self):
return NotImplemented
x = Shorty()
+x.len()
len(x)
if __debug__:
diff --git a/test/markup/python/matrix-multiplication.expect.txt b/test/markup/python/matrix-multiplication.expect.txt
index 91ad4b9261..6a5f334e4c 100644
--- a/test/markup/python/matrix-multiplication.expect.txt
+++ b/test/markup/python/matrix-multiplication.expect.txt
@@ -3,5 +3,5 @@
@decorator
def f(self, H, V, beta, r):
- S = (H @ beta - r).T @ inv(H @ V @ H.T) @ (H @ beta - r)
+ S = (H @ beta - r).T @ inv(H @ V @ H.T) @ (H @ beta - r)
return S
diff --git a/test/markup/python/numbers.expect.txt b/test/markup/python/numbers.expect.txt
index 725eb354f7..65530608ea 100644
--- a/test/markup/python/numbers.expect.txt
+++ b/test/markup/python/numbers.expect.txt
@@ -29,7 +29,7 @@
-0..__str__, 1e1.__str__, fn(.5)
+0..__str__, 1e1.__str__, fn(.5)
0is 0, 0lis 0
0_0_0is 0, 0_0_0lis 0
0b0is 0, 0b0lis 0
@@ -50,7 +50,7 @@
0_0_0jis 0, 0_0_9jis 0
-x0.j
+x0.j
1__0