From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dario Gjorgjevski Newsgroups: gmane.emacs.bugs Subject: bug#51362: python font-lock-mode in emacs 28 seems broken Date: Thu, 11 Nov 2021 09:04:01 +0100 Message-ID: References: <87bl35v8pl.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000003b53e905d07ecbab" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="352"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Jeff Spencer , 51362@debbugs.gnu.org, Stefan Kangas To: =?UTF-8?Q?K=C3=A9vin?= Le Gouguec Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Nov 11 09:05:42 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ml55Z-000AMA-Sy for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 11 Nov 2021 09:05:41 +0100 Original-Received: from localhost ([::1]:54196 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ml55Y-000349-AJ for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 11 Nov 2021 03:05:40 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:40538) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ml54w-00032B-CM for bug-gnu-emacs@gnu.org; Thu, 11 Nov 2021 03:05:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:56784) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1ml54w-0002JV-41 for bug-gnu-emacs@gnu.org; Thu, 11 Nov 2021 03:05:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ml54v-0000hf-Vc for bug-gnu-emacs@gnu.org; Thu, 11 Nov 2021 03:05:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Dario Gjorgjevski Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 11 Nov 2021 08:05:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51362 X-GNU-PR-Package: emacs Original-Received: via spool by 51362-submit@debbugs.gnu.org id=B51362.16366178862664 (code B ref 51362); Thu, 11 Nov 2021 08:05:01 +0000 Original-Received: (at 51362) by debbugs.gnu.org; 11 Nov 2021 08:04:46 +0000 Original-Received: from localhost ([127.0.0.1]:40094 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ml54g-0000gn-DZ for submit@debbugs.gnu.org; Thu, 11 Nov 2021 03:04:46 -0500 Original-Received: from mail-ed1-f50.google.com ([209.85.208.50]:43759) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ml54d-0000gT-OI for 51362@debbugs.gnu.org; Thu, 11 Nov 2021 03:04:44 -0500 Original-Received: by mail-ed1-f50.google.com with SMTP id w1so20940678edd.10 for <51362@debbugs.gnu.org>; Thu, 11 Nov 2021 00:04:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=jsbR+PDiKWJewaz/dPmZhsChTjlqW3+cDDa5gbtm5Rc=; b=JM1hfyLlsPz9qEfJn0F9IjsEY09NlqzFEm5+V3YVDlvOrE/R5OHRMbHTiM8D/xSIYW tyLDE693hvKGYxNG+ogOs8KsRugkGZsrgSROgflMSAD3m2fV9NKLbLLVeCTxKZDYpN/e IBbHuO7hPgZovTOwhFNpOALnjAnh121iylEAF5J9woRGI43HoGx99aBu5FCf8VvJqBf5 eFtv8Aeju+Jb+zApt3r98W7R6kzLs/Ltp61540gE+FizfhBYIJFjxp6IhIe5Kxo2LLKp 2EhtxfL0hoG8VEd7V1QwpUnh8+v6wxdbmHSPmng6SKc3O68NMG3yNDWY6CwZrCaZXCO4 yNwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=jsbR+PDiKWJewaz/dPmZhsChTjlqW3+cDDa5gbtm5Rc=; b=bstbKHTHOhn9BaKUdAJwAOijT7yRl5eLocBVfx+VSDFW37Mxaj/6ncvXegkzL6F5HC tZDTNLrfq/QGxhWzsai5EGdn5PWkgUvIX+RCJ1xvsQaI+QElEbW6BUsLNdBCHQ1F/Uhb XJXQSCYybuo4s+TgYsO4AAoyxwkFe6KM4hvtbxtYmW2qNw9S5JVTiO9oL67s4QZgrnz/ 5UHGNkvTegnL+4UiShQrZUq7j5Lxsn3/kMdFf8xJ9m7nURMEbh/5aGiGj68yPQMuuczy nGRt/UHIxZmfpmHPveAFeigpZMGfY0IYcG6sDC/vGAIFXbPz9j6OdlIQx+HFJqDmgoJX p/Bw== X-Gm-Message-State: AOAM531/KZbFjnugeRG4EU8Gf12jNYZOt+WftKReV3FLcfRF0Hfsod28 YOYHA0mxEick1s5Vz7C1ortYgyRz3zAJpmPI/bI= X-Google-Smtp-Source: ABdhPJyNjsRPLQUpP2YjCkEWRKvRiX+BpgKN4AHwiwoJ3kZXweMTbE2OKWqPEPRrwdPfO4lcA6f/2vCMZ1VqSys+Vio= X-Received: by 2002:a05:6402:27ca:: with SMTP id c10mr7471756ede.53.1636617877671; Thu, 11 Nov 2021 00:04:37 -0800 (PST) In-Reply-To: <87bl35v8pl.fsf@gmail.com> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:219612 Archived-At: --0000000000003b53e905d07ecbab Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 '=3D' sign (to avoid '=3D=3D' 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)) ?=3D)))) 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 =3D int def f(x: CustomInt) -> CustomInt: y =3D x + 1 ys: Sequence[CustomInt] =3D [y, y + 1] res: CustomInt =3D sum(ys) + 1 return res When such a file is first opened: - The y in y =3D x + 1 is not highlighted =E2=80=94 this is fixed by sub= sequent edits - The CustomInt in -> CustomInt is highlighted =E2=80=94 this is fixed b= y subsequent edits - The CustomInt in Sequence[CustomInt] is highlighted =E2=80=94 this is = *not* fixed by subsequent edits These are caused by the type hints (in the case of 1. =E2=80=94 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 --0000000000003b53e905d07ecbab Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi,

Thanks a lot for the report and the reproducer, and sorry for t= he 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-l= ock-assignment-matcher is giving up too early.
Replacing its definition by
(defun python-font-lock-assignment-matcher (re= gexp)
=C2=A0 "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 trea= ted as assignments) or is followed by an '=3D' sign (to
avoid &#= 39;=3D=3D' being treated as an assignment."
=C2=A0 (lambda (lim= it)
=C2=A0 =C2=A0 (let ((res nil))
=C2=A0 =C2=A0 =C2=A0 (while (and (= setq res (re-search-forward regexp limit t))
=C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (or (python-syntax-context 'paren)<= br>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 (equal (char-after (point)) ?=3D))))
=C2=A0 =C2=A0 =C2=A0 res)))<= /span>
should fix the issue.
Would you be able to g= ive it a try?

Unfortunately so= me issues still remain, all of which can be illustrated by a file containin= g the following code:
CustomInt =3D int

def f(x: Custo= mInt) -> CustomInt:
=C2=A0 =C2=A0 y =3D x + 1
=C2=A0 =C2=A0 ys: Se= quence[CustomInt] =3D [y, y + 1]
=C2=A0 =C2=A0 res: CustomInt =3D sum(ys= ) + 1
=C2=A0 =C2=A0 return res
When such a file= is first opened:
  • The y in y = =3D x + 1 is not highlighted =E2=80=94 this is fixed by subsequent e= dits
  • The CustomInt in = -> CustomInt is highlighted= =E2=80=94 this is fixed by subsequent edits
  • The CustomInt in Sequence[CustomInt] is highlighted =E2=80=94 this is not f= ixed by subsequent edits
These are caused by the type hints (= in the case of 1. =E2=80=94 by the type hints in the function's signatu= re).
I am not sure how one would fix them.

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

Best regards,
Dario
--0000000000003b53e905d07ecbab--