New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update handling of Python decorators #2811
Conversation
Playing a bit more with it, PEP614 makes this all-but impossible in the general case. Either comments are counted as part of the decorator, you have to implement arbitrary expression parsing in regex, or some of the decorator gets missed out. Some examples below comparing pre- and post-PR Highlight.js as well as GitHub's formatting: On GitHub: @commented # here
def func():
pass
@py38.style
def func():
pass
@py[3.9].style
def func():
pass
@2 + 2 == 5
def func():
pass In Highlight.js without this PR: In Highlight.js with this PR: Notes:
Questions:
|
Ok, let's forget about what's technically possible and look at how people typically use this instead. Every single example on the PEP614 page is a contiguous string of characters... What about:
So comments would be possible anywhere after the contiguous string of characters was broken... If you got really creative you could even allow for
Should this ALL be a single color or should the string and numeric be matched as such? |
Or (if we aren't highlighting) could we just add STRING inside |
Yep, that was the trick - when I'd experimented with ending on a Pre-PR: GitHub: @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 Post-PR: |
Ok, so the mode nesting solves the issue with comments, but now what about visually... do we want to see them as meta or styled as they are in any other code (like how you have it now). |
I like it with the literal strings and numbers with the non-meta styling, as GitHub does it on the |
I'm happy with what we have now unless you want to go poll some other peoples... |
Before [PEP614] decorators had to be a dotted name. [1]: https://www.python.org/dev/peps/pep-0614/
Me too! Let's ship it, the visuals can always be updated later if desired. |
If you're looking for more fun with Python: #2633 |
Resolves #2804.
Changes
Modifies the
meta
matching for Python code to handle decorators more accurately. This allows e.g. comments to be correctly formatted in lines starting with@
.Checklist
CHANGES.md
AUTHORS.txt
, under Contributors