Stefan Kangas <stefankangas@HIDDEN>
to control <at> debbugs.gnu.org
.
Full text available.Received: (at 69357) by debbugs.gnu.org; 18 May 2024 20:24:36 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Sat May 18 16:24:36 2024 Received: from localhost ([127.0.0.1]:35467 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1s8Qbc-0002GE-6W for submit <at> debbugs.gnu.org; Sat, 18 May 2024 16:24:36 -0400 Received: from mail-ed1-f43.google.com ([209.85.208.43]:43351) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <stefankangas@HIDDEN>) id 1s8Qba-0002G1-Uc for 69357 <at> debbugs.gnu.org; Sat, 18 May 2024 16:24:35 -0400 Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-572baf393ddso8409018a12.1 for <69357 <at> debbugs.gnu.org>; Sat, 18 May 2024 13:24:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716063805; x=1716668605; darn=debbugs.gnu.org; h=to:subject:message-id:date:mime-version:references:in-reply-to:from :from:to:cc:subject:date:message-id:reply-to; bh=Y9mIY/viSUdKJKt610P8Maym/NDgB/TLmkW4C/B3/SA=; b=NazGFIi69RHc85UZzHJZrDw4XiVJiVlCWTlp6RlTssc8iqglkQBb47cJQum4Rqs6Kd 88OcjO3Y1AdezotVWIs/J4Y9RL6CxuP24Rdzib8XVhWhIdtVSOLoDYJUI0gzC8L8n5Kq +IDb0pUczY9wxHfnHPV+IAPip/fPOsIhP9ipS5F03izXMoY2nYo74sZyJmY+oj3JvrH7 y5S5bgkodsllW+OGgfkg3yXVLWqIZHjPZoCLpA6/jjx8RvWUjkfl/3xyKWplXimmT+5n cUwU6Gt9snkuQTaIsbVwjCfE79ii40bDqMSbOxbg27micbOozGtl2Ly9Yt0csCcZpf7c oQgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716063805; x=1716668605; h=to:subject:message-id:date:mime-version:references:in-reply-to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Y9mIY/viSUdKJKt610P8Maym/NDgB/TLmkW4C/B3/SA=; b=Y74RkYSS2lnWgKxyb9RodWYQQIRqwr6c9orhHtgNc0g1HqpTgEHKgjvl3ylCQNPyGs qUk9f0ZTfONdrqpElAxEZ3GKeK65Akvy3szNVJLnz2o//g7TvKHAfdquBGo471gJw3++ ZXkqs8lWkmOIsx17KF1sqbLLQZ6SEfd0gIFX2+x8+epEtp2lA6M4z966bYnQiCOunanV uhm/AGlTqMIUKKJHKWrFsIXW9xhdtUh77ZFcg4y4LJD7AvlFDtbPkgUDLhoYNR4gCFEl ubWyj8dYKOg29GQC6+DFQWa1VaCW9GWhAe98hcGapJgUcI1PoNjaYpZeHDgIKxJ7KAzm BV5Q== X-Forwarded-Encrypted: i=1; AJvYcCU9gXDM7mO3ddZhYCyUu02iymGmCCItAKbpN/aoDXVNWPfFmUKhsdHQjSPJxSo9P0RdI4UEaHpK2azbwL6zYwHILRBvRKU= X-Gm-Message-State: AOJu0YzNPDPHxJVjrV8NNXBpw+Kkdhf5Mfmq/7k7RfscfWG77fbdjw21 wZFbcLg6s1OvwxsqOIIFo6wV6tC8seqW4ME3TYLXuFS1dJEK3zi+cVvQG1tZP2WAG5ulw2i5CmG ecjTy2tCio93B6tcGkE1YgjfSOEw= X-Google-Smtp-Source: AGHT+IE9FlEZV4rC1QEQFjsMhbps/ozmzhbIT+thXjBRthDoS6226/EzH5OrnZwwqs/6Mk1iMiB+O207kcdTmTAeGlY= X-Received: by 2002:a50:cc9d:0:b0:574:fda9:883a with SMTP id 4fb4d7f45d1cf-5752b4c9285mr2052820a12.15.1716063805489; Sat, 18 May 2024 13:23:25 -0700 (PDT) Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Sat, 18 May 2024 20:23:24 +0000 From: Stefan Kangas <stefankangas@HIDDEN> In-Reply-To: <eke74jdy6iw0.wl-kobarity@HIDDEN> References: <eke74jdy6iw0.wl-kobarity@HIDDEN> MIME-Version: 1.0 Date: Sat, 18 May 2024 20:23:24 +0000 Message-ID: <CADwFkmki_V30n_iS-Q71y8rAX2esnOTAqfWrayiMSJ16vL6afg@HIDDEN> Subject: Re: bug#69357: [PATCH] Improve fontification of Python assignment statement with type hints To: kobarity <kobarity@HIDDEN>, 69357 <at> debbugs.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 69357 X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.0 (-) close 69357 30.1 thanks kobarity <kobarity@HIDDEN> writes: > In python-mode (not python-ts-mode), "List" in the type hints of the > following code are fontified as variable names. > > #+begin_src python > a: List[List[CustomInt], List[CustomInt]] = [] > #+end_src > > This is due to misinterpretation as a multiple assignment statement > such as: > > #+begin_src python > a, b = 1, 2 > #+end_src > > To address this issue and to improve fontification, I suggest to > fontify type hints in the assignment statement as type names before > processing multiple assignment statements, as in the attached patch. Your analysis seems correct, and the fix works here. It's very nice to see tests for this too, as always. Thus, I've now pushed your change to master (commit c97e7a2da2e). I'm consequently closing this bug report. Thanks for your contribution!
bug-gnu-emacs@HIDDEN
:bug#69357
; Package emacs
.
Full text available.Received: (at submit) by debbugs.gnu.org; 24 Feb 2024 14:24:06 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Sat Feb 24 09:24:06 2024 Received: from localhost ([127.0.0.1]:59508 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1rdswf-0001Gr-Fw for submit <at> debbugs.gnu.org; Sat, 24 Feb 2024 09:24:06 -0500 Received: from lists.gnu.org ([209.51.188.17]:35886) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <kobarity@HIDDEN>) id 1rdswd-0001Gi-7N for submit <at> debbugs.gnu.org; Sat, 24 Feb 2024 09:24:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <kobarity@HIDDEN>) id 1rdswD-0002IZ-VQ for bug-gnu-emacs@HIDDEN; Sat, 24 Feb 2024 09:23:38 -0500 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from <kobarity@HIDDEN>) id 1rdsw9-0007Od-6F for bug-gnu-emacs@HIDDEN; Sat, 24 Feb 2024 09:23:37 -0500 Received: by mail-pl1-x62d.google.com with SMTP id d9443c01a7336-1dc49afb495so11396635ad.2 for <bug-gnu-emacs@HIDDEN>; Sat, 24 Feb 2024 06:23:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708784611; x=1709389411; darn=gnu.org; h=mime-version:user-agent:subject:to:from:message-id:date:from:to:cc :subject:date:message-id:reply-to; bh=YrB1goaZwT4k20x+oXziJ7AWXHcXUJmzjATJjgEevcE=; b=AzUEbfRViTjpk6du/5RsHM7joUMDdkqow86bL7gwHsmZSZyKRms4zmgklWteF/nb3y ZsUFnAdBbhMxVQjfk6Ff+z1HM9i29Swm0tA9FNil30vP4DP9Gz5dktUHWaxLpq+eVBAa 9ikmJ+ccpMfm3udku3VrpSdUCAMd6kYjDfJrnY2by3JmMskGYuRFYjiPdfJAATv6Zxqy aO3MO39bIXBzWVs99bxlRcKWNCLccraRqt9unDH1ogiPgmGL8QAleRy6vr7RMSRW4WQZ +/iNsdZeuLeYcnX/WANON2/bWgS7VPStzngHxzjCv85vQxyUFFqxnp3ZvUTC/ea4wcfK Ru1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708784611; x=1709389411; h=mime-version:user-agent:subject:to:from:message-id:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=YrB1goaZwT4k20x+oXziJ7AWXHcXUJmzjATJjgEevcE=; b=mjWhSvPAgVWT4Pshdnr40m3c+myMsaE8nSMqz3lZM8eqPKISmu66UQk1323A5x4Iba sjnKFWKGWuL9J7Puzct1IT9LT1IIU6cWl/g9MaHR6YKZR/BRINkF8gAYlK5D2tZsP4GS Sb5ZAoxfDxGCk7QKJ8hUdoI3qkOQeXyxo548H7wwkZcNkENPrPOkljm6sruive5rIDit u2dXMSZLye0FUSgom2NL5Ls1djs0/JEnLrHglzJG2Zye+aAXf0fkdL/qaDj9U3nyYnwF cuRmABtZ/ATmMPrKfkLuw/G3rnb3tST+iCm9PFmPJYHtyN3SGBogsHm2KfomFAyB+Sm4 yjhw== X-Gm-Message-State: AOJu0YyFMjVX06HtuIjvbXqBSUslCc52Ec7Q831TJ+dFTCgIrwsaPVDD 4fiTjVe0OGiumxekH7wflZKBuLrobUv/uriex5h0vg0c8hxVlXrONyQ1wMDM X-Google-Smtp-Source: AGHT+IFC5lLw6W3pmeUh3g6AL4D7SPb4FG1lkQiKW/Ah7zv0QSQ+510YD7M689UhQnf5g2IM4KeclA== X-Received: by 2002:a17:902:d491:b0:1db:dd24:9940 with SMTP id c17-20020a170902d49100b001dbdd249940mr3849966plg.40.1708784611064; Sat, 24 Feb 2024 06:23:31 -0800 (PST) Received: from localhost (58x12x133x161.ap58.ftth.ucom.ne.jp. [58.12.133.161]) by smtp.gmail.com with ESMTPSA id pd7-20020a17090b1dc700b0029696f7f443sm3306981pjb.50.2024.02.24.06.23.29 for <bug-gnu-emacs@HIDDEN> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 06:23:30 -0800 (PST) Date: Sat, 24 Feb 2024 23:23:27 +0900 Message-ID: <eke74jdy6iw0.wl-kobarity@HIDDEN> From: kobarity <kobarity@HIDDEN> To: bug-gnu-emacs@HIDDEN Subject: [PATCH] Improve fontification of Python assignment statement with type hints User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?ISO-8859-4?Q?Goj=F2?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.0.50 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: multipart/mixed; boundary="Multipart_Sat_Feb_24_23:23:27_2024-1" Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=kobarity@HIDDEN; helo=mail-pl1-x62d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -2.3 (--) --Multipart_Sat_Feb_24_23:23:27_2024-1 Content-Type: text/plain; charset=US-ASCII In python-mode (not python-ts-mode), "List" in the type hints of the following code are fontified as variable names. #+begin_src python a: List[List[CustomInt], List[CustomInt]] = [] #+end_src This is due to misinterpretation as a multiple assignment statement such as: #+begin_src python a, b = 1, 2 #+end_src To address this issue and to improve fontification, I suggest to fontify type hints in the assignment statement as type names before processing multiple assignment statements, as in the attached patch. -- In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo version 1.16.0, Xaw scroll bars) of 2024-02-24 built on ubuntu Repository revision: eeb89a5cb292bffe40ba7d0b0cf81f82f8452bf8 Repository branch: master System Description: Ubuntu 22.04.4 LTS --Multipart_Sat_Feb_24_23:23:27_2024-1 Content-Type: text/plain; type=patch; name="0001-Improve-fontification-of-Python-assignment-statement.patch"; charset=US-ASCII Content-Disposition: attachment; filename="0001-Improve-fontification-of-Python-assignment-statement.patch" Content-Transfer-Encoding: 7bit From 801e51e91d56606b3f017a3916519d26956353e7 Mon Sep 17 00:00:00 2001 From: kobarity <kobarity@HIDDEN> Date: Sat, 24 Feb 2024 23:11:02 +0900 Subject: [PATCH] Improve fontification of Python assignment statement with type hints * lisp/progmodes/python.el (python-font-lock-keywords-maximum-decoration): Fontify type hints of assignment statement. * test/lisp/progmodes/python-tests.el (python-font-lock-assignment-statement-11) (python-font-lock-assignment-statement-12) (python-font-lock-assignment-statement-13) (python-font-lock-assignment-statement-18): Add fontification of type hints. (python-font-lock-assignment-statement-19): New test. --- lisp/progmodes/python.el | 31 ++++++++++++++++++----------- test/lisp/progmodes/python-tests.el | 20 +++++++++++++++++++ 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index bedc61408ef..074d2e25dd1 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -790,6 +790,25 @@ python-font-lock-keywords-maximum-decoration ) symbol-end) . font-lock-type-face) + ;; single assignment with/without type hints, e.g. + ;; a: int = 5 + ;; b: Tuple[Optional[int], Union[Sequence[str], str]] = (None, 'foo') + ;; c: Collection = {1, 2, 3} + ;; d: Mapping[int, str] = {1: 'bar', 2: 'baz'} + (,(python-font-lock-assignment-matcher + (python-rx (or line-start ?\;) (* space) + grouped-assignment-target (* space) + (? ?: (* space) (group (+ not-simple-operator)) (* space)) + (group assignment-operator))) + (1 font-lock-variable-name-face) + (3 'font-lock-operator-face) + (,(python-rx symbol-name) + (progn + (when-let ((type-start (match-beginning 2))) + (goto-char type-start)) + (match-end 0)) + nil + (0 font-lock-type-face))) ;; multiple assignment ;; (note that type hints are not allowed for multiple assignments) ;; a, b, c = 1, 2, 3 @@ -822,18 +841,6 @@ python-font-lock-keywords-maximum-decoration (match-beginning 2)) ; limit the search until the assignment nil (1 font-lock-variable-name-face))) - ;; single assignment with type hints, e.g. - ;; a: int = 5 - ;; b: Tuple[Optional[int], Union[Sequence[str], str]] = (None, 'foo') - ;; c: Collection = {1, 2, 3} - ;; d: Mapping[int, str] = {1: 'bar', 2: 'baz'} - (,(python-font-lock-assignment-matcher - (python-rx (or line-start ?\;) (* space) - grouped-assignment-target (* space) - (? ?: (* space) (+ not-simple-operator) (* space)) - (group assignment-operator))) - (1 font-lock-variable-name-face) - (2 'font-lock-operator-face)) ;; special cases ;; (a) = 5 ;; [a] = 5, diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index 6c6cd9eee2b..8c7cfe196d2 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el @@ -385,7 +385,11 @@ python-font-lock-assignment-statement-11 (python-tests-assert-faces "b: Tuple[Optional[int], Union[Sequence[str], str]] = (None, 'foo')" '((1 . font-lock-variable-name-face) (2) + (4 . font-lock-type-face) (9) + (10 . font-lock-type-face) (18) (19 . font-lock-builtin-face) (22) + (25 . font-lock-type-face) (30) + (31 . font-lock-type-face) (39) (40 . font-lock-builtin-face) (43) (46 . font-lock-builtin-face) (49) (52 . font-lock-operator-face) (53) @@ -396,12 +400,14 @@ python-font-lock-assignment-statement-12 (python-tests-assert-faces "c: Collection = {1, 2, 3}" '((1 . font-lock-variable-name-face) (2) + (4 . font-lock-type-face) (14) (15 . font-lock-operator-face) (16)))) (ert-deftest python-font-lock-assignment-statement-13 () (python-tests-assert-faces "d: Mapping[int, str] = {1: 'bar', 2: 'baz'}" '((1 . font-lock-variable-name-face) (2) + (4 . font-lock-type-face) (11) (12 . font-lock-builtin-face) (15) (17 . font-lock-builtin-face) (20) (22 . font-lock-operator-face) (23) @@ -466,14 +472,28 @@ python-font-lock-assignment-statement-18 (58 . font-lock-operator-face) (59) (62 . font-lock-operator-face) (63) (70 . font-lock-variable-name-face) (72) + (74 . font-lock-type-face) (82) + (83 . font-lock-type-face) (92) (94 . font-lock-operator-face) (95) (102 . font-lock-operator-face) (103) (111 . font-lock-variable-name-face) (114) + (116 . font-lock-type-face) (125) (126 . font-lock-operator-face) (127) (128 . font-lock-builtin-face) (131) (136 . font-lock-operator-face) (137) (144 . font-lock-keyword-face) (150)))) +(ert-deftest python-font-lock-assignment-statement-19 () + (python-tests-assert-faces + "a: List[List[CustomInt], List[CustomInt]] = []" + '((1 . font-lock-variable-name-face) (2) + (4 . font-lock-type-face) (8) + (9 . font-lock-type-face) (13) + (14 . font-lock-type-face) (23) + (26 . font-lock-type-face) (30) + (31 . font-lock-type-face) (40) + (43 . font-lock-operator-face) (44)))) + (ert-deftest python-font-lock-operator-1 () (python-tests-assert-faces "1 << 2 ** 3 == +4%-5|~6&7^8%9" -- 2.34.1 --Multipart_Sat_Feb_24_23:23:27_2024-1--
kobarity <kobarity@HIDDEN>
:bug-gnu-emacs@HIDDEN
.
Full text available.bug-gnu-emacs@HIDDEN
:bug#69357
; Package emacs
.
Full text available.
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997 nCipher Corporation Ltd,
1994-97 Ian Jackson.