GNU bug report logs -
#56757
29.0.50; Python f-string font-lock logic is incomplete
Previous Next
Reported by: Dima Kogan <dima <at> secretsauce.net>
Date: Mon, 25 Jul 2022 09:07:02 UTC
Severity: wishlist
Tags: moreinfo, patch
Found in version 29.0.50
Fixed in version 29.1
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 56757 in the body.
You can then email your comments to 56757 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#56757; Package
emacs.
(Mon, 25 Jul 2022 09:07:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Dima Kogan <dima <at> secretsauce.net>:
New bug report received and forwarded. Copy sent to
bug-gnu-emacs <at> gnu.org.
(Mon, 25 Jul 2022 09:07:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Hi. Currently python-mode has syntax highlighting to display the part of
the string being interpolated (the {...} stuff) differently from the
rest of the string. The emacs python-mode has logic to detect f-strings
to turn this highlighting on/off properly. It looks like this logic is
incomplete, however: it doesn't handle ''' and """ and r strings. (It
doesn't handle b strings either, but fb'asdf' is not legal Python, so
that's fine).
This is legal Python, and {x} is expanded to '5' in each case when the
program is executed.
x = 5
ss = (f'''aaa {x} bbb''',
fr'''aaa {x} bbb''',
rf'''aaa {x} bbb''',
f"""aaa {x} bbb""",
fr"""aaa {x} bbb""",
rf"""aaa {x} bbb""",
f'aaa {x} bbb', # this is highlighted properly
fr'aaa {x} bbb',
rf'aaa {x} bbb',
f"aaa {x} bbb", # this is highlighted properly
fr"aaa {x} bbb",
rf"aaa {x} bbb",)
for s in ss:
print(s)
However the {x} is highlighted as code only on the lines marked above.
The other lines should have this highlighting also.
Thanks!
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#56757; Package
emacs.
(Sat, 30 Jul 2022 17:11:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 56757 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Hi, I've attached a patch which looks good to me locally using the above
examples and others.
In addition to the above, mixed capitalizations are also covered:
https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals
.
Thanks!
[Message part 2 (text/html, inline)]
[0001-Apply-syntax-highlighting-for-all-python-f-strings.patch (text/x-patch, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#56757; Package
emacs.
(Sat, 30 Jul 2022 17:11:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 56757 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Hi, I've attached a patch which looks good to me locally using the above
examples and others.
In addition to the above, mixed capitalizations are also covered:
https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals
.
Thanks!
[Message part 2 (text/html, inline)]
[0001-Apply-syntax-highlighting-for-all-python-f-strings.patch (text/x-patch, attachment)]
Severity set to 'wishlist' from 'normal'
Request was from
Stefan Kangas <stefan <at> marxist.se>
to
control <at> debbugs.gnu.org.
(Thu, 04 Aug 2022 13:59:07 GMT)
Full text and
rfc822 format available.
Added tag(s) patch.
Request was from
Stefan Kangas <stefan <at> marxist.se>
to
control <at> debbugs.gnu.org.
(Thu, 04 Aug 2022 13:59:07 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#56757; Package
emacs.
(Mon, 05 Sep 2022 19:14:02 GMT)
Full text and
rfc822 format available.
Message #18 received at 56757 <at> debbugs.gnu.org (full text, mbox):
Laurence Warne <laurencewarne <at> gmail.com> writes:
> Hi, I've attached a patch which looks good to me locally using the above examples
> and others.
>
> In addition to the above, mixed capitalizations are also covered:
> https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals.
I think your patch makes sense, but it leads to failures in:
1 unexpected results:
FAILED python-font-lock-escape-sequence-multiline-string
Could you have a look at that and possibly adjust the test too (if it's
the test that's wrong here)?
Added tag(s) moreinfo.
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org.
(Mon, 05 Sep 2022 19:14:02 GMT)
Full text and
rfc822 format available.
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#56757; Package
emacs.
(Tue, 06 Sep 2022 10:09:02 GMT)
Full text and
rfc822 format available.
Message #23 received at 56757 <at> debbugs.gnu.org (full text, mbox):
[Message part 1 (text/plain, inline)]
Hi, I've attached a patch fixing up this test. The difference occurred with:
rf"""\x12 S \n \u1234 \U00010348 \N{Plus-Minus Sign}"""
(and equivalent variants: the same string but starting with fr""", fr''',
rf''').
The patch treats "{Plus-Minus Sign}" as an embedded expression within an
f-string, causing it to be fontified differently (previously it was
fontified the same as the rest of the string). This is invalid syntax
since "Plus-Minus Sign" is not a valid expression, so I think it's the
correct behaviour since it emphasises that "{Plus-Minus Sign}" will be
treated as an embedded expression even though it's invalid.
I hope that makes sense, thanks, Laurence
On Mon, Sep 5, 2022 at 8:13 PM Lars Ingebrigtsen <larsi <at> gnus.org> wrote:
> Laurence Warne <laurencewarne <at> gmail.com> writes:
>
> > Hi, I've attached a patch which looks good to me locally using the above
> examples
> > and others.
> >
> > In addition to the above, mixed capitalizations are also covered:
> >
> https://docs.python.org/3/reference/lexical_analysis.html#string-and-bytes-literals
> .
>
> I think your patch makes sense, but it leads to failures in:
>
> 1 unexpected results:
> FAILED python-font-lock-escape-sequence-multiline-string
>
> Could you have a look at that and possibly adjust the test too (if it's
> the test that's wrong here)?
>
>
[Message part 2 (text/html, inline)]
[0001-Apply-syntax-highlighting-for-all-python-f-strings.patch (text/x-patch, attachment)]
Information forwarded
to
bug-gnu-emacs <at> gnu.org:
bug#56757; Package
emacs.
(Tue, 06 Sep 2022 10:29:01 GMT)
Full text and
rfc822 format available.
Message #26 received at 56757 <at> debbugs.gnu.org (full text, mbox):
Laurence Warne <laurencewarne <at> gmail.com> writes:
> I hope that makes sense, thanks, Laurence
It does indeed. I've now pushed your patch to Emacs 29.
bug marked as fixed in version 29.1, send any further explanations to
56757 <at> debbugs.gnu.org and Dima Kogan <dima <at> secretsauce.net>
Request was from
Lars Ingebrigtsen <larsi <at> gnus.org>
to
control <at> debbugs.gnu.org.
(Tue, 06 Sep 2022 10:29:02 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org.
(Tue, 04 Oct 2022 11:24:07 GMT)
Full text and
rfc822 format available.
This bug report was last modified 3 years and 43 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.