diff --git a/CHANGES.md b/CHANGES.md
index b6fdef3eff..5947bb45c1 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -22,6 +22,7 @@ Parser Engine Changes:
Language Improvements:
+- enh(python) Exclude parens from functions params (#2490) [Álvaro Mondéjar][]
- enh(swift) Add `compactMap` to keywords as built_in (#2478) [Omid Golparvar][]
- enh(nim) adds `func` keyword (#2468) [Adnan Yaqoob][]
- enh(xml) deprecate ActionScript inside script tags (#2444) [Josh Goebel][]
@@ -70,6 +71,7 @@ Developer Tools:
[Josh Goebel]: https://github.com/yyyc514
[Sean Williams]: https://github.com/hmmwhatsthisdo
[Adnan Yaqoob]: https://github.com/adnanyaqoobvirk
+[Álvaro Mondéjar]: https://github.com/mondeja
## Version 9.18.1
@@ -2148,4 +2150,3 @@ your comments and question to [highlight.js forum][forum]. And don't be afraid
if you find there some fancy Cyrillic letters -- it's for Russian users too :-)
[forum]: http://softwaremaniacs.org/forum/viewforum.php?id=6
-
diff --git a/src/languages/python.js b/src/languages/python.js
index e7ae1bf222..86e5d32066 100644
--- a/src/languages/python.js
+++ b/src/languages/python.js
@@ -86,8 +86,14 @@ export default function(hljs) {
};
var PARAMS = {
className: 'params',
- begin: /\(/, end: /\)/,
- contains: ['self', PROMPT, NUMBER, STRING, hljs.HASH_COMMENT_MODE]
+ variants: [
+ // Exclude params at functions without params
+ {begin: /\(\s*\)/, skip: true, className: null },
+ {
+ begin: /\(/, end: /\)/, excludeBegin: true, excludeEnd: true,
+ contains: ['self', PROMPT, NUMBER, STRING, hljs.HASH_COMMENT_MODE],
+ },
+ ],
};
SUBST.contains = [STRING, NUMBER, PROMPT];
return {
diff --git a/test/markup/python-repl/sample.expect.txt b/test/markup/python-repl/sample.expect.txt
index d5695847b8..6693b43cf9 100644
--- a/test/markup/python-repl/sample.expect.txt
+++ b/test/markup/python-repl/sample.expect.txt
@@ -11,7 +11,7 @@ foo = 42"
>>> """
... abc
... """
->>> def test():
+>>> def test():
... pass
>>>
>>>
diff --git a/test/markup/python/function-header-comments.expect.txt b/test/markup/python/function-header-comments.expect.txt
index b8530371f2..4ebe4aaad6 100644
--- a/test/markup/python/function-header-comments.expect.txt
+++ b/test/markup/python/function-header-comments.expect.txt
@@ -1,10 +1,10 @@
-def foo(
+def foo(
bar,
-):
+):
pass
-class Foo(collections.namedtuple('Test'), (
+class Foo(collections.namedtuple('Test'), (
'name',
-)):
- pass
\ No newline at end of file
+)):
+ pass
diff --git a/test/markup/python/function-header.expect.txt b/test/markup/python/function-header.expect.txt
index cf3c8e5ef9..eb249617df 100644
--- a/test/markup/python/function-header.expect.txt
+++ b/test/markup/python/function-header.expect.txt
@@ -1,2 +1,2 @@
-def f(x: int) -> None:
+def f(x: int) -> None:
pass
diff --git a/test/markup/python/matrix-multiplication.expect.txt b/test/markup/python/matrix-multiplication.expect.txt
index 97323a195b..256895b24e 100644
--- a/test/markup/python/matrix-multiplication.expect.txt
+++ b/test/markup/python/matrix-multiplication.expect.txt
@@ -2,6 +2,6 @@
class C:
@decorator
- def f(self, H, V, beta, r):
+ def f(self, H, V, beta, r):
S = (H @ beta - r).T @ inv(H @ V @ H.T) @ (H @ beta - r)
return S