unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Dario Gjorgjevski <dario.gjorgjevski@gmail.com>
To: "Kévin Le Gouguec" <kevin.legouguec@gmail.com>
Cc: Jeff Spencer <jeffspencerd@gmail.com>,
	51362@debbugs.gnu.org, Stefan Kangas <stefan@marxist.se>
Subject: bug#51362: python font-lock-mode in emacs 28 seems broken
Date: Thu, 11 Nov 2021 09:04:01 +0100	[thread overview]
Message-ID: <CAJm4QYPhW9oeZ6sttc5PEu=RBHChj5CFrq1B_AVmGHMMxEmcQA@mail.gmail.com> (raw)
In-Reply-To: <87bl35v8pl.fsf@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1853 bytes --]

Hi,

Thanks a lot for the report and the reproducer, and sorry for the
regression that my patch introduced.
It has been a while since I wrote any Python, so I did not notice it.

What seems to be happening is that python-font-lock-assignment-matcher is
giving up too early.
Replacing its definition by
(defun python-font-lock-assignment-matcher (regexp)
  "Font lock matcher for assignments based on REGEXP.
Return nil if REGEXP matched within a `paren' context (to avoid,
e.g., default values for arguments or passing arguments by name
being treated as assignments) or is followed by an '=' sign (to
avoid '==' being treated as an assignment."
  (lambda (limit)
    (let ((res nil))
      (while (and (setq res (re-search-forward regexp limit t))
                  (or (python-syntax-context 'paren)
                      (equal (char-after (point)) ?=))))
      res)))
should fix the issue.
Would you be able to give it a try?

Unfortunately some issues still remain, all of which can be illustrated by
a file containing the following code:
CustomInt = int

def f(x: CustomInt) -> CustomInt:
    y = x + 1
    ys: Sequence[CustomInt] = [y, y + 1]
    res: CustomInt = sum(ys) + 1
    return res
When such a file is first opened:

   - The y in y = x + 1 is not highlighted — this is fixed by subsequent
   edits
   - The CustomInt in -> CustomInt is highlighted — this is fixed by
   subsequent edits
   - The CustomInt in Sequence[CustomInt] is highlighted — this is *not*
   fixed by subsequent edits

These are caused by the type hints (in the case of 1. — by the type hints
in the function's signature).
I am not sure how one would fix them.

Regarding reverting the patch: It can be done easily, but the previous code
had even more bugs happening around type hints.

Best regards,
Dario

[-- Attachment #2: Type: text/html, Size: 3101 bytes --]

  reply	other threads:[~2021-11-11  8:04 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-23 20:06 bug#51362: python font-lock-mode in emacs 28 seems broken Jeff Spencer
2021-10-24 12:45 ` Stefan Kangas
2021-10-24 22:37   ` Jeff Spencer
2021-10-24 22:40     ` Jeff Spencer
2021-10-31  9:34   ` Kévin Le Gouguec
2021-11-11  8:04     ` Dario Gjorgjevski [this message]
2021-11-11  8:48       ` Stefan Kangas
2021-11-11 12:37       ` Lars Ingebrigtsen
2022-04-17 23:32 ` kobarity
2022-04-18  9:50   ` Lars Ingebrigtsen
2022-04-18 12:34     ` kobarity
2022-04-18 12:36       ` Lars Ingebrigtsen
2022-05-16 13:40         ` Lars Ingebrigtsen
2022-05-16 14:21           ` kobarity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAJm4QYPhW9oeZ6sttc5PEu=RBHChj5CFrq1B_AVmGHMMxEmcQA@mail.gmail.com' \
    --to=dario.gjorgjevski@gmail.com \
    --cc=51362@debbugs.gnu.org \
    --cc=jeffspencerd@gmail.com \
    --cc=kevin.legouguec@gmail.com \
    --cc=stefan@marxist.se \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).