From unknown Sun Jun 22 11:43:15 2025 X-Loop: help-debbugs@gnu.org Subject: bug#68284: [PATCH] Fix python-info-docstring-p bug in the 2nd line of a buffer Resent-From: kobarity Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 06 Jan 2024 13:14:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 68284 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch To: 68284@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.170454678319910 (code B ref -1); Sat, 06 Jan 2024 13:14:01 +0000 Received: (at submit) by debbugs.gnu.org; 6 Jan 2024 13:13:03 +0000 Received: from localhost ([127.0.0.1]:58806 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rM6U3-0005B3-AB for submit@debbugs.gnu.org; Sat, 06 Jan 2024 08:13:03 -0500 Received: from lists.gnu.org ([2001:470:142::17]:44380) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rM6U1-0005AX-Gu for submit@debbugs.gnu.org; Sat, 06 Jan 2024 08:13:02 -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 ) id 1rM6Tq-0005uV-Pd for bug-gnu-emacs@gnu.org; Sat, 06 Jan 2024 08:12:51 -0500 Received: from mail-oi1-x22b.google.com ([2607:f8b0:4864:20::22b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rM6Tp-0005jT-2y for bug-gnu-emacs@gnu.org; Sat, 06 Jan 2024 08:12:50 -0500 Received: by mail-oi1-x22b.google.com with SMTP id 5614622812f47-3bbce1202ebso544708b6e.2 for ; Sat, 06 Jan 2024 05:12:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704546767; x=1705151567; darn=gnu.org; h=mime-version:user-agent:subject:to:from:message-id:date:from:to:cc :subject:date:message-id:reply-to; bh=Rd+5NWQveDuvclMF71SQ1zjCEQT9sK/KIjs81z4XsJE=; b=LSgp/bskgvAqLmsxnKFfpcDdxZR2pIovxj3ERzldxzdSTHN8rJucM1NcFD6w1r7zf8 PychwoCIvbZNDfJpu4M5NvK7gSdSKqnPvRg64XlvDmhjFJS6G97HjNrxJEpmcfdz0h/3 yg/VZZIgjDlY5yTKQ3uCaQm3gRxHstclwwXDEk5wY6fjozkdmsK8QZJBHWBL3wjwVqtB OEu9CbQrM7NS6Rl8fu+yKugOkpBvGHHeiEZ5tiBsbOHLXOMFH8ETM/t6Gw8jM/uTlLGn iR/3iPrM+OAHl5i6DcMMd1Xc1LFsl2qpH1uqbTwXzAZRFX3uOudNvJoQ5CNpUOEljh3s Gj1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704546767; x=1705151567; 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=Rd+5NWQveDuvclMF71SQ1zjCEQT9sK/KIjs81z4XsJE=; b=NQzgnNsUBP5nvS+989N58ycEbktxPEYB77wfMzyRQKaZuHjgOPOmQQxJKBGllgmCZH pAOrA6NAptgsfatNiEb3beCftirdWjI5ro7oLMkvSjRFAhOCar2NAvStdI6LsSQT6jCu PhJEvIEruQh+AIy524USiGZjKDd/M4sumJbXDI+ANvAq2a1muHHVFx4slnFWxVRYbDE8 tDQQlt5fIJXUSwNtKnGPKqTNesKNRyf3toH9wROD7I/wjjrgt82OWbHi1NToPmjD1TZG +E5urBMPk31NOWJ7bMaYCtTEyKffQAC01oBOp8hF4bCMGQfHKPEX3QhlKp9avzsX3hWo +yUQ== X-Gm-Message-State: AOJu0Yxv6QjUlIEsKTXmE9S25z0QrlybpaY6v17mPh1u4UqsGqNNA22A sWNs0VFGEZpk7oH9u6AUbgk3uhf8Mbk= X-Google-Smtp-Source: AGHT+IGy1pbhRMP/k/z9rjPGElnCnmvyhP46CL1zn7HJHx3I5TIl4W0EN0aLWj5DGKtmmkk6kEZS6g== X-Received: by 2002:a05:6808:1709:b0:3bd:1ff9:b430 with SMTP id bc9-20020a056808170900b003bd1ff9b430mr894862oib.61.1704546767186; Sat, 06 Jan 2024 05:12:47 -0800 (PST) Received: from localhost (58x12x133x161.ap58.ftth.ucom.ne.jp. [58.12.133.161]) by smtp.gmail.com with ESMTPSA id fd4-20020a056a002e8400b006daaf9d7856sm3008379pfb.219.2024.01.06.05.12.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jan 2024 05:12:46 -0800 (PST) Date: Sat, 06 Jan 2024 22:12:36 +0900 Message-ID: From: kobarity User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?Q?Goj=C5=8D?=) 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_Jan__6_22:12:36_2024-1" Received-SPF: pass client-ip=2607:f8b0:4864:20::22b; envelope-from=kobarity@gmail.com; helo=mail-oi1-x22b.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.0 (+) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) --Multipart_Sat_Jan__6_22:12:36_2024-1 Content-Type: text/plain; charset=US-ASCII Hi, No matter what the first line of the buffer is, if the second line is a string literal, `python-info-docstring-p` will misjudge it as a docstring. This issue can be reproduced as follows: 1. emacs -Q 2. Open a Python file whose contents are as follows: #+begin_src python import sys """Not a docstring.""" #+end_src 3. Locate the point at the string literal on the second line. 4. M-: (python-info-docstring-p) Although this string literal is not a docstring, it returns t. Therefore, in `python-mode` (not `python-ts-mode`), this string literal is rendered in `font-lock-doc-face`. This is the reason I changed some ERTs to "expected fail" in the commit b7b82ecb2b4c2ce33c11e5388b692cd403ab55e6 of Bug#63622. Attached is a patch to fix this bug and the above mentioned ERTs and to restore ERTs I deleted by mistake in commit 6b2c8dc9050c5c0514fa404733ce1d4a37d00e39 of Bug#63844 (related to Bug#63622). -- In GNU Emacs 30.0.50 (build 3, x86_64-pc-linux-gnu, X toolkit, cairo version 1.16.0, Xaw scroll bars) of 2024-01-03 built on ubuntu Repository revision: 91bc775b0c60342f118640001d2ce293d4f1f7ef Repository branch: master System Description: Ubuntu 22.04.3 LTS --Multipart_Sat_Jan__6_22:12:36_2024-1 Content-Type: application/octet-stream; type=patch; name="0001-Fix-python-info-docstring-p-bug-in-the-2nd-line-of-a.patch" Content-Disposition: attachment; filename="0001-Fix-python-info-docstring-p-bug-in-the-2nd-line-of-a.patch" Content-Transfer-Encoding: 7bit >From a292abf5ef41483df24323c36b0c97802df9d9d6 Mon Sep 17 00:00:00 2001 From: kobarity Date: Sat, 6 Jan 2024 22:04:42 +0900 Subject: [PATCH] Fix python-info-docstring-p bug in the 2nd line of a buffer * lisp/progmodes/python.el (python-info-docstring-p): Add looking-at-p check when bobp. * test/lisp/progmodes/python-tests.el (python-font-lock-operator-1) (python-font-lock-operator-2): Restoration of ERTs deleted by mistake. (python-font-lock-escape-sequence-bytes-newline) (python-font-lock-escape-sequence-hex-octal) (python-font-lock-escape-sequence-unicode) (python-font-lock-raw-escape-sequence): Change font-lock-doc-face to font-lock-string-face and remove :expected-result :failed. (python-info-docstring-p-8): New test. --- lisp/progmodes/python.el | 4 +- test/lisp/progmodes/python-tests.el | 73 ++++++++++++++++++++--------- 2 files changed, 53 insertions(+), 24 deletions(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 1148da11a06..a44d4215d7c 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -6260,7 +6260,9 @@ python-info-docstring-p counter))) (python-util-forward-comment -1) (python-nav-beginning-of-statement) - (cond ((bobp)) + (cond ((and (bobp) (save-excursion + (python-util-forward-comment) + (looking-at-p re)))) ((python-info-assignment-statement-p) t) ((python-info-looking-at-beginning-of-defun)) (t nil)))))) diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index 1df0c42a0ce..97ffd5fe20f 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el @@ -474,6 +474,28 @@ python-font-lock-assignment-statement-18 (136 . font-lock-operator-face) (137) (144 . font-lock-keyword-face) (150)))) +(ert-deftest python-font-lock-operator-1 () + (python-tests-assert-faces + "1 << 2 ** 3 == +4%-5|~6&7^8%9" + '((1) + (3 . font-lock-operator-face) (5) + (8 . font-lock-operator-face) (10) + (13 . font-lock-operator-face) (15) + (16 . font-lock-operator-face) (17) + (18 . font-lock-operator-face) (20) + (21 . font-lock-operator-face) (23) + (24 . font-lock-operator-face) (25) + (26 . font-lock-operator-face) (27) + (28 . font-lock-operator-face) (29)))) + +(ert-deftest python-font-lock-operator-2 () + "Keyword operators are font-locked as keywords." + (python-tests-assert-faces + "is_ is None" + '((1) + (5 . font-lock-keyword-face) (7) + (8 . font-lock-constant-face)))) + (ert-deftest python-font-lock-escape-sequence-string-newline () (python-tests-assert-faces "'\\n' @@ -585,62 +607,58 @@ python-font-lock-escape-sequence-multiline-string (845 . font-lock-string-face) (886)))) (ert-deftest python-font-lock-escape-sequence-bytes-newline () - :expected-result :failed (python-tests-assert-faces "b'\\n' b\"\\n\"" '((1) - (2 . font-lock-doc-face) + (2 . font-lock-string-face) (3 . font-lock-constant-face) - (5 . font-lock-doc-face) (6) - (8 . font-lock-doc-face) + (5 . font-lock-string-face) (6) + (8 . font-lock-string-face) (9 . font-lock-constant-face) - (11 . font-lock-doc-face)))) + (11 . font-lock-string-face)))) (ert-deftest python-font-lock-escape-sequence-hex-octal () - :expected-result :failed (python-tests-assert-faces "b'\\x12 \\777 \\1\\23' '\\x12 \\777 \\1\\23'" '((1) - (2 . font-lock-doc-face) + (2 . font-lock-string-face) (3 . font-lock-constant-face) - (7 . font-lock-doc-face) + (7 . font-lock-string-face) (8 . font-lock-constant-face) - (12 . font-lock-doc-face) + (12 . font-lock-string-face) (13 . font-lock-constant-face) - (18 . font-lock-doc-face) (19) - (20 . font-lock-doc-face) + (18 . font-lock-string-face) (19) + (20 . font-lock-string-face) (21 . font-lock-constant-face) - (25 . font-lock-doc-face) + (25 . font-lock-string-face) (26 . font-lock-constant-face) - (30 . font-lock-doc-face) + (30 . font-lock-string-face) (31 . font-lock-constant-face) - (36 . font-lock-doc-face)))) + (36 . font-lock-string-face)))) (ert-deftest python-font-lock-escape-sequence-unicode () - :expected-result :failed (python-tests-assert-faces "b'\\u1234 \\U00010348 \\N{Plus-Minus Sign}' '\\u1234 \\U00010348 \\N{Plus-Minus Sign}'" '((1) - (2 . font-lock-doc-face) (41) - (42 . font-lock-doc-face) + (2 . font-lock-string-face) (41) + (42 . font-lock-string-face) (43 . font-lock-constant-face) - (49 . font-lock-doc-face) + (49 . font-lock-string-face) (50 . font-lock-constant-face) - (60 . font-lock-doc-face) + (60 . font-lock-string-face) (61 . font-lock-constant-face) - (80 . font-lock-doc-face)))) + (80 . font-lock-string-face)))) (ert-deftest python-font-lock-raw-escape-sequence () - :expected-result :failed (python-tests-assert-faces "rb'\\x12 \123 \\n' r'\\x12 \123 \\n \\u1234 \\U00010348 \\N{Plus-Minus Sign}'" '((1) - (3 . font-lock-doc-face) (14) - (16 . font-lock-doc-face)))) + (3 . font-lock-string-face) (14) + (16 . font-lock-string-face)))) ;;; Indentation @@ -6647,6 +6665,15 @@ python-info-docstring-p-7 (python-tests-look-at "Also not a docstring") (should-not (python-info-docstring-p)))) +(ert-deftest python-info-docstring-p-8 () + "Test string in the 2nd line of a buffer." + (python-tests-with-temp-buffer + "import sys +'''Not a docstring.''' +" + (python-tests-look-at "Not a docstring") + (should-not (python-info-docstring-p)))) + (ert-deftest python-info-triple-quoted-string-p-1 () "Test triple quoted string." (python-tests-with-temp-buffer -- 2.34.1 --Multipart_Sat_Jan__6_22:12:36_2024-1-- From unknown Sun Jun 22 11:43:15 2025 MIME-Version: 1.0 X-Mailer: MIME-tools 5.505 (Entity 5.505) X-Loop: help-debbugs@gnu.org From: help-debbugs@gnu.org (GNU bug Tracking System) To: kobarity Subject: bug#68284: closed (Re: bug#68284: [PATCH] Fix python-info-docstring-p bug in the 2nd line of a buffer) Message-ID: References: <83edelh901.fsf@gnu.org> X-Gnu-PR-Message: they-closed 68284 X-Gnu-PR-Package: emacs X-Gnu-PR-Keywords: patch Reply-To: 68284@debbugs.gnu.org Date: Sat, 13 Jan 2024 09:36:02 +0000 Content-Type: multipart/mixed; boundary="----------=_1705138562-31199-1" This is a multi-part message in MIME format... ------------=_1705138562-31199-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Your bug report #68284: [PATCH] Fix python-info-docstring-p bug in the 2nd line of a buffer which was filed against the emacs package, has been closed. The explanation is attached below, along with your original report. If you require more details, please reply to 68284@debbugs.gnu.org. --=20 68284: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3D68284 GNU Bug Tracking System Contact help-debbugs@gnu.org with problems ------------=_1705138562-31199-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at 68284-done) by debbugs.gnu.org; 13 Jan 2024 09:35:09 +0000 Received: from localhost ([127.0.0.1]:38413 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rOaQ1-00085U-8m for submit@debbugs.gnu.org; Sat, 13 Jan 2024 04:35:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56604) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rOaPz-00085E-9v for 68284-done@debbugs.gnu.org; Sat, 13 Jan 2024 04:35:07 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rOaPs-0006ZB-AR; Sat, 13 Jan 2024 04:35:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=tM6S2cu4hFSgPDYaYbbaR6OFRCiZohhNUs3Ky0nYIL8=; b=LaBkSklAPDpX llI4xQVUlUCGdqqeXBOmP218LxcDeEKXfLICeFadySCSeSgjvWuPacJjTpsYLBX/t6vym3sgyWQuQ jFmN6qAotvrv0gokXnQgM127Ykmg9ffay5Hi84HKkXXFuJvHnvKFObgGztUoHL168Z3XP5G9blpPO AtoDGv1ByGe7E9ThGMCb+9GW2m3bS/VQM6wr5SiwGWvExUh7BZY26FCF1ixzU+Ql9GvoxZlFmMMIZ +XRQUE9TKPAxP4a4hIVYqHFbfHZETFa4+S/gnK2j0ITuR19vWxWf5b4H9W7WKLXMX5fqzcuGC09UW 4pFtOlgoxGBz5e+YhCZ01A==; Date: Sat, 13 Jan 2024 11:34:38 +0200 Message-Id: <83edelh901.fsf@gnu.org> From: Eli Zaretskii To: kobarity In-Reply-To: (message from kobarity on Sat, 06 Jan 2024 22:12:36 +0900) Subject: Re: bug#68284: [PATCH] Fix python-info-docstring-p bug in the 2nd line of a buffer References: X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 68284-done Cc: 68284-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Date: Sat, 06 Jan 2024 22:12:36 +0900 > From: kobarity > > No matter what the first line of the buffer is, if the second line is > a string literal, `python-info-docstring-p` will misjudge it as a > docstring. This issue can be reproduced as follows: > > 1. emacs -Q > 2. Open a Python file whose contents are as follows: > > #+begin_src python > import sys > """Not a docstring.""" > #+end_src > > 3. Locate the point at the string literal on the second line. > 4. M-: (python-info-docstring-p) > > Although this string literal is not a docstring, it returns t. > Therefore, in `python-mode` (not `python-ts-mode`), this string > literal is rendered in `font-lock-doc-face`. > > This is the reason I changed some ERTs to "expected fail" in the > commit b7b82ecb2b4c2ce33c11e5388b692cd403ab55e6 of Bug#63622. > > Attached is a patch to fix this bug and the above mentioned ERTs and > to restore ERTs I deleted by mistake in commit > 6b2c8dc9050c5c0514fa404733ce1d4a37d00e39 of Bug#63844 (related to > Bug#63622). Thanks, installed on the master branch, and closing the bug. ------------=_1705138562-31199-1 Content-Type: message/rfc822 Content-Disposition: inline Content-Transfer-Encoding: 7bit Received: (at submit) by debbugs.gnu.org; 6 Jan 2024 13:13:03 +0000 Received: from localhost ([127.0.0.1]:58806 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rM6U3-0005B3-AB for submit@debbugs.gnu.org; Sat, 06 Jan 2024 08:13:03 -0500 Received: from lists.gnu.org ([2001:470:142::17]:44380) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rM6U1-0005AX-Gu for submit@debbugs.gnu.org; Sat, 06 Jan 2024 08:13:02 -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 ) id 1rM6Tq-0005uV-Pd for bug-gnu-emacs@gnu.org; Sat, 06 Jan 2024 08:12:51 -0500 Received: from mail-oi1-x22b.google.com ([2607:f8b0:4864:20::22b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rM6Tp-0005jT-2y for bug-gnu-emacs@gnu.org; Sat, 06 Jan 2024 08:12:50 -0500 Received: by mail-oi1-x22b.google.com with SMTP id 5614622812f47-3bbce1202ebso544708b6e.2 for ; Sat, 06 Jan 2024 05:12:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704546767; x=1705151567; darn=gnu.org; h=mime-version:user-agent:subject:to:from:message-id:date:from:to:cc :subject:date:message-id:reply-to; bh=Rd+5NWQveDuvclMF71SQ1zjCEQT9sK/KIjs81z4XsJE=; b=LSgp/bskgvAqLmsxnKFfpcDdxZR2pIovxj3ERzldxzdSTHN8rJucM1NcFD6w1r7zf8 PychwoCIvbZNDfJpu4M5NvK7gSdSKqnPvRg64XlvDmhjFJS6G97HjNrxJEpmcfdz0h/3 yg/VZZIgjDlY5yTKQ3uCaQm3gRxHstclwwXDEk5wY6fjozkdmsK8QZJBHWBL3wjwVqtB OEu9CbQrM7NS6Rl8fu+yKugOkpBvGHHeiEZ5tiBsbOHLXOMFH8ETM/t6Gw8jM/uTlLGn iR/3iPrM+OAHl5i6DcMMd1Xc1LFsl2qpH1uqbTwXzAZRFX3uOudNvJoQ5CNpUOEljh3s Gj1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704546767; x=1705151567; 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=Rd+5NWQveDuvclMF71SQ1zjCEQT9sK/KIjs81z4XsJE=; b=NQzgnNsUBP5nvS+989N58ycEbktxPEYB77wfMzyRQKaZuHjgOPOmQQxJKBGllgmCZH pAOrA6NAptgsfatNiEb3beCftirdWjI5ro7oLMkvSjRFAhOCar2NAvStdI6LsSQT6jCu PhJEvIEruQh+AIy524USiGZjKDd/M4sumJbXDI+ANvAq2a1muHHVFx4slnFWxVRYbDE8 tDQQlt5fIJXUSwNtKnGPKqTNesKNRyf3toH9wROD7I/wjjrgt82OWbHi1NToPmjD1TZG +E5urBMPk31NOWJ7bMaYCtTEyKffQAC01oBOp8hF4bCMGQfHKPEX3QhlKp9avzsX3hWo +yUQ== X-Gm-Message-State: AOJu0Yxv6QjUlIEsKTXmE9S25z0QrlybpaY6v17mPh1u4UqsGqNNA22A sWNs0VFGEZpk7oH9u6AUbgk3uhf8Mbk= X-Google-Smtp-Source: AGHT+IGy1pbhRMP/k/z9rjPGElnCnmvyhP46CL1zn7HJHx3I5TIl4W0EN0aLWj5DGKtmmkk6kEZS6g== X-Received: by 2002:a05:6808:1709:b0:3bd:1ff9:b430 with SMTP id bc9-20020a056808170900b003bd1ff9b430mr894862oib.61.1704546767186; Sat, 06 Jan 2024 05:12:47 -0800 (PST) Received: from localhost (58x12x133x161.ap58.ftth.ucom.ne.jp. [58.12.133.161]) by smtp.gmail.com with ESMTPSA id fd4-20020a056a002e8400b006daaf9d7856sm3008379pfb.219.2024.01.06.05.12.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jan 2024 05:12:46 -0800 (PST) Date: Sat, 06 Jan 2024 22:12:36 +0900 Message-ID: From: kobarity To: bug-gnu-emacs@gnu.org Subject: [PATCH] Fix python-info-docstring-p bug in the 2nd line of a buffer 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_Jan__6_22:12:36_2024-1" Received-SPF: pass client-ip=2607:f8b0:4864:20::22b; envelope-from=kobarity@gmail.com; helo=mail-oi1-x22b.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.0 (+) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.0 (/) --Multipart_Sat_Jan__6_22:12:36_2024-1 Content-Type: text/plain; charset=US-ASCII Hi, No matter what the first line of the buffer is, if the second line is a string literal, `python-info-docstring-p` will misjudge it as a docstring. This issue can be reproduced as follows: 1. emacs -Q 2. Open a Python file whose contents are as follows: #+begin_src python import sys """Not a docstring.""" #+end_src 3. Locate the point at the string literal on the second line. 4. M-: (python-info-docstring-p) Although this string literal is not a docstring, it returns t. Therefore, in `python-mode` (not `python-ts-mode`), this string literal is rendered in `font-lock-doc-face`. This is the reason I changed some ERTs to "expected fail" in the commit b7b82ecb2b4c2ce33c11e5388b692cd403ab55e6 of Bug#63622. Attached is a patch to fix this bug and the above mentioned ERTs and to restore ERTs I deleted by mistake in commit 6b2c8dc9050c5c0514fa404733ce1d4a37d00e39 of Bug#63844 (related to Bug#63622). -- In GNU Emacs 30.0.50 (build 3, x86_64-pc-linux-gnu, X toolkit, cairo version 1.16.0, Xaw scroll bars) of 2024-01-03 built on ubuntu Repository revision: 91bc775b0c60342f118640001d2ce293d4f1f7ef Repository branch: master System Description: Ubuntu 22.04.3 LTS --Multipart_Sat_Jan__6_22:12:36_2024-1 Content-Type: application/octet-stream; type=patch; name="0001-Fix-python-info-docstring-p-bug-in-the-2nd-line-of-a.patch" Content-Disposition: attachment; filename="0001-Fix-python-info-docstring-p-bug-in-the-2nd-line-of-a.patch" Content-Transfer-Encoding: 7bit >From a292abf5ef41483df24323c36b0c97802df9d9d6 Mon Sep 17 00:00:00 2001 From: kobarity Date: Sat, 6 Jan 2024 22:04:42 +0900 Subject: [PATCH] Fix python-info-docstring-p bug in the 2nd line of a buffer * lisp/progmodes/python.el (python-info-docstring-p): Add looking-at-p check when bobp. * test/lisp/progmodes/python-tests.el (python-font-lock-operator-1) (python-font-lock-operator-2): Restoration of ERTs deleted by mistake. (python-font-lock-escape-sequence-bytes-newline) (python-font-lock-escape-sequence-hex-octal) (python-font-lock-escape-sequence-unicode) (python-font-lock-raw-escape-sequence): Change font-lock-doc-face to font-lock-string-face and remove :expected-result :failed. (python-info-docstring-p-8): New test. --- lisp/progmodes/python.el | 4 +- test/lisp/progmodes/python-tests.el | 73 ++++++++++++++++++++--------- 2 files changed, 53 insertions(+), 24 deletions(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 1148da11a06..a44d4215d7c 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -6260,7 +6260,9 @@ python-info-docstring-p counter))) (python-util-forward-comment -1) (python-nav-beginning-of-statement) - (cond ((bobp)) + (cond ((and (bobp) (save-excursion + (python-util-forward-comment) + (looking-at-p re)))) ((python-info-assignment-statement-p) t) ((python-info-looking-at-beginning-of-defun)) (t nil)))))) diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index 1df0c42a0ce..97ffd5fe20f 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el @@ -474,6 +474,28 @@ python-font-lock-assignment-statement-18 (136 . font-lock-operator-face) (137) (144 . font-lock-keyword-face) (150)))) +(ert-deftest python-font-lock-operator-1 () + (python-tests-assert-faces + "1 << 2 ** 3 == +4%-5|~6&7^8%9" + '((1) + (3 . font-lock-operator-face) (5) + (8 . font-lock-operator-face) (10) + (13 . font-lock-operator-face) (15) + (16 . font-lock-operator-face) (17) + (18 . font-lock-operator-face) (20) + (21 . font-lock-operator-face) (23) + (24 . font-lock-operator-face) (25) + (26 . font-lock-operator-face) (27) + (28 . font-lock-operator-face) (29)))) + +(ert-deftest python-font-lock-operator-2 () + "Keyword operators are font-locked as keywords." + (python-tests-assert-faces + "is_ is None" + '((1) + (5 . font-lock-keyword-face) (7) + (8 . font-lock-constant-face)))) + (ert-deftest python-font-lock-escape-sequence-string-newline () (python-tests-assert-faces "'\\n' @@ -585,62 +607,58 @@ python-font-lock-escape-sequence-multiline-string (845 . font-lock-string-face) (886)))) (ert-deftest python-font-lock-escape-sequence-bytes-newline () - :expected-result :failed (python-tests-assert-faces "b'\\n' b\"\\n\"" '((1) - (2 . font-lock-doc-face) + (2 . font-lock-string-face) (3 . font-lock-constant-face) - (5 . font-lock-doc-face) (6) - (8 . font-lock-doc-face) + (5 . font-lock-string-face) (6) + (8 . font-lock-string-face) (9 . font-lock-constant-face) - (11 . font-lock-doc-face)))) + (11 . font-lock-string-face)))) (ert-deftest python-font-lock-escape-sequence-hex-octal () - :expected-result :failed (python-tests-assert-faces "b'\\x12 \\777 \\1\\23' '\\x12 \\777 \\1\\23'" '((1) - (2 . font-lock-doc-face) + (2 . font-lock-string-face) (3 . font-lock-constant-face) - (7 . font-lock-doc-face) + (7 . font-lock-string-face) (8 . font-lock-constant-face) - (12 . font-lock-doc-face) + (12 . font-lock-string-face) (13 . font-lock-constant-face) - (18 . font-lock-doc-face) (19) - (20 . font-lock-doc-face) + (18 . font-lock-string-face) (19) + (20 . font-lock-string-face) (21 . font-lock-constant-face) - (25 . font-lock-doc-face) + (25 . font-lock-string-face) (26 . font-lock-constant-face) - (30 . font-lock-doc-face) + (30 . font-lock-string-face) (31 . font-lock-constant-face) - (36 . font-lock-doc-face)))) + (36 . font-lock-string-face)))) (ert-deftest python-font-lock-escape-sequence-unicode () - :expected-result :failed (python-tests-assert-faces "b'\\u1234 \\U00010348 \\N{Plus-Minus Sign}' '\\u1234 \\U00010348 \\N{Plus-Minus Sign}'" '((1) - (2 . font-lock-doc-face) (41) - (42 . font-lock-doc-face) + (2 . font-lock-string-face) (41) + (42 . font-lock-string-face) (43 . font-lock-constant-face) - (49 . font-lock-doc-face) + (49 . font-lock-string-face) (50 . font-lock-constant-face) - (60 . font-lock-doc-face) + (60 . font-lock-string-face) (61 . font-lock-constant-face) - (80 . font-lock-doc-face)))) + (80 . font-lock-string-face)))) (ert-deftest python-font-lock-raw-escape-sequence () - :expected-result :failed (python-tests-assert-faces "rb'\\x12 \123 \\n' r'\\x12 \123 \\n \\u1234 \\U00010348 \\N{Plus-Minus Sign}'" '((1) - (3 . font-lock-doc-face) (14) - (16 . font-lock-doc-face)))) + (3 . font-lock-string-face) (14) + (16 . font-lock-string-face)))) ;;; Indentation @@ -6647,6 +6665,15 @@ python-info-docstring-p-7 (python-tests-look-at "Also not a docstring") (should-not (python-info-docstring-p)))) +(ert-deftest python-info-docstring-p-8 () + "Test string in the 2nd line of a buffer." + (python-tests-with-temp-buffer + "import sys +'''Not a docstring.''' +" + (python-tests-look-at "Not a docstring") + (should-not (python-info-docstring-p)))) + (ert-deftest python-info-triple-quoted-string-p-1 () "Test triple quoted string." (python-tests-with-temp-buffer -- 2.34.1 --Multipart_Sat_Jan__6_22:12:36_2024-1-- ------------=_1705138562-31199-1--