Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enh(python) Improve handling of decorators (#2811)
Modifies the meta matching for Python code to handle decorators more accurately. This allows e.g. comments to be correctly formatted on lines starting with `@`.
- Loading branch information
Showing
6 changed files
with
68 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<span class="hljs-meta">@foo</span> | ||
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">bar</span>():</span> | ||
<span class="hljs-keyword">pass</span> | ||
|
||
<span class="hljs-meta">@foo </span><span class="hljs-comment"># bar</span> | ||
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">baz</span>():</span> | ||
<span class="hljs-keyword">pass</span> | ||
|
||
<span class="hljs-meta">@foo.bar.baz</span> | ||
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">qux</span>():</span> | ||
<span class="hljs-keyword">pass</span> | ||
|
||
<span class="hljs-meta">@surround_with(<span class="hljs-params"><span class="hljs-string">"#"</span>, repeat=<span class="hljs-number">3</span></span>)</span> | ||
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">text</span>():</span> | ||
<span class="hljs-keyword">return</span> <span class="hljs-string">"hi!"</span> | ||
|
||
<span class="hljs-meta">@py38.style</span> | ||
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">func</span>():</span> | ||
<span class="hljs-keyword">pass</span> | ||
|
||
<span class="hljs-meta">@py[<span class="hljs-string">"3.9"</span>].style</span> | ||
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">func</span>():</span> | ||
<span class="hljs-keyword">pass</span> | ||
|
||
<span class="hljs-meta">@py[<span class="hljs-number">3.9</span>].style</span> | ||
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">func</span>():</span> | ||
<span class="hljs-keyword">pass</span> | ||
|
||
<span class="hljs-meta">@<span class="hljs-number">2</span> + <span class="hljs-number">2</span> == <span class="hljs-number">5</span></span> | ||
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">func</span>():</span> | ||
<span class="hljs-keyword">pass</span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
@foo | ||
def bar(): | ||
pass | ||
|
||
@foo # bar | ||
def baz(): | ||
pass | ||
|
||
@foo.bar.baz | ||
def qux(): | ||
pass | ||
|
||
@surround_with("#", repeat=3) | ||
def text(): | ||
return "hi!" | ||
|
||
@py38.style | ||
def func(): | ||
pass | ||
|
||
@py["3.9"].style | ||
def func(): | ||
pass | ||
|
||
@py[3.9].style | ||
def func(): | ||
pass | ||
|
||
@2 + 2 == 5 | ||
def func(): | ||
pass |