GNU bug report logs -
#63622
lisp/progmodes/python.el: performance regression introduced by multiline font-lock
Previous Next
Reported by: Tom Gillespie <tgbugs <at> gmail.com>
Date: Sun, 21 May 2023 03:15:02 UTC
Severity: normal
Done: Eli Zaretskii <eliz <at> gnu.org>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Ruijie Yu wrote:
> On May 23, 2023, at 23:46, kobarity <kobarity <at> gmail.com> wrote:
> > The performance problem in the example shown by Tom can be resolved by
> > modifying the above code as follows:
> >
> > (re (concat "[uU]?[rR]?"
> > (rx (or "\"\"\"" "\"" "'''" "'")))))
>
> I didn’t read the context for this snippet, but isn’t it sufficient to match for only one single-quote and double-quote, instead of also matching for the triple (multiline) counterparts?
You are right. I copied the above code from the definition of
python-rx string-delimiter. However, it was inside of the group
construct. As group capturing is not needed in
python-info-docstring-p, the regex can be simplified to:
(re "[uU]?[rR]?[\"']"))
The same regex was used in another place in python-info-docstring-p.
So I fixed it too. Also I added a simple ERT to identify this fix.
I wrote:
> It breaks some ERTs, but I think we should fix the ERTs. However,
> there seems to be another problem in python-info-docstring-p. It
> intentionally considers contiguous strings as docstring as in the ERT
> python-info-docstring-p-1:
>
> '''
> Module Docstring Django style.
> '''
> u'''Additional module docstring.'''
> '''Not a module docstring.'''
>
> However, as far as I have tried with Python 3 and Python 2.7, this is
> not correct.
This was my misunderstanding. PEP-257
(https://www.python.org/dev/peps/pep-0257/#what-is-a-docstring)
clearly states:
#+begin_quote
String literals occurring elsewhere in Python code may also act as
documentation. They are not recognized by the Python bytecode compiler
and are not accessible as runtime object attributes (i.e. not assigned
to __doc__), but two types of extra docstrings may be extracted by
software tools:
1. String literals occurring immediately after a simple assignment at
the top level of a module, class, or __init__ method are called
“attribute docstrings”.
2. String literals occurring immediately after another docstring are
called “additional docstrings”.
#+end_quote
However, there still seems to be a bug in python-info-docstring-p.
Therefore, I would like to keep failing ERTs as expected fail at this
time. Maybe f-string can also be a docstring.
Attached is a series of patches that replace the previous patches.
[0001-Fix-python-info-docstring-p.patch (application/octet-stream, attachment)]
[0002-Use-font-lock-extend-region-functions-in-python-mode.patch (application/octet-stream, attachment)]
This bug report was last modified 1 year and 361 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.