Skip to content

Commit

Permalink
(python) don't include ( ) in functions params match (#2490)
Browse files Browse the repository at this point in the history
- Before: `<params>(x,y,z)</params>`
- After: `(<params>x,y,z</params>)`

Improves consistency with other grammars.
  • Loading branch information
mondeja committed Apr 11, 2020
1 parent 512ae5f commit 30deab1
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CHANGES.md
Expand Up @@ -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][]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

10 changes: 8 additions & 2 deletions src/languages/python.js
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion test/markup/python-repl/sample.expect.txt
Expand Up @@ -11,7 +11,7 @@ foo = 42"
<span class="hljs-meta">&gt;&gt;&gt;</span> <span class="python"><span class="hljs-string">"""</span></span>
<span class="hljs-meta">...</span> <span class="python"><span class="hljs-string">abc</span></span>
<span class="hljs-meta">...</span> <span class="python"><span class="hljs-string">"""</span></span>
<span class="hljs-meta">&gt;&gt;&gt;</span> <span class="python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test</span><span class="hljs-params">()</span>:</span></span>
<span class="hljs-meta">&gt;&gt;&gt;</span> <span class="python"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">test</span>():</span></span>
<span class="hljs-meta">...</span> <span class="python"> <span class="hljs-keyword">pass</span></span>
<span class="hljs-meta">&gt;&gt;&gt;</span>
<span class="hljs-meta">&gt;&gt;&gt;</span>
10 changes: 5 additions & 5 deletions test/markup/python/function-header-comments.expect.txt
@@ -1,10 +1,10 @@
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">foo</span><span class="hljs-params">(
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">foo</span>(<span class="hljs-params">
bar, <span class="hljs-comment"># commment</span>
)</span>:</span>
</span>):</span>
<span class="hljs-keyword">pass</span>


<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Foo</span><span class="hljs-params">(collections.namedtuple<span class="hljs-params">(<span class="hljs-string">'Test'</span>)</span>, <span class="hljs-params">(
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Foo</span>(<span class="hljs-params">collections.namedtuple(<span class="hljs-params"><span class="hljs-string">'Test'</span></span>), (<span class="hljs-params">
<span class="hljs-string">'name'</span>, <span class="hljs-comment"># comment</span>
)</span>)</span>:</span>
<span class="hljs-keyword">pass</span>
</span>)</span>):</span>
<span class="hljs-keyword">pass</span>
2 changes: 1 addition & 1 deletion test/markup/python/function-header.expect.txt
@@ -1,2 +1,2 @@
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">f</span><span class="hljs-params">(x: int)</span> -&gt; <span class="hljs-keyword">None</span>:</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">f</span>(<span class="hljs-params">x: int</span>) -&gt; <span class="hljs-keyword">None</span>:</span>
<span class="hljs-keyword">pass</span>
2 changes: 1 addition & 1 deletion test/markup/python/matrix-multiplication.expect.txt
Expand Up @@ -2,6 +2,6 @@
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">C</span>:</span>

<span class="hljs-meta"> @decorator</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">f</span><span class="hljs-params">(self, H, V, beta, r)</span>:</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">f</span>(<span class="hljs-params">self, H, V, beta, r</span>):</span>
S = (H @ beta - r).T @ inv(H @ V @ H.T) @ (H @ beta - r)
<span class="hljs-keyword">return</span> S

0 comments on commit 30deab1

Please sign in to comment.