GNU bug report logs - #65870
30.0.50; Error in python-mode when try to delete a character in badly-indented code

Previous Next

Package: emacs;

Reported by: Daniel Lopez <daniel.lopez999 <at> gmail.com>

Date: Mon, 11 Sep 2023 16:38:01 UTC

Severity: normal

Found in version 30.0.50

Done: Eli Zaretskii <eliz <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 65870 in the body.
You can then email your comments to 65870 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#65870; Package emacs. (Mon, 11 Sep 2023 16:38:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Daniel Lopez <daniel.lopez999 <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 11 Sep 2023 16:38:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Daniel Lopez <daniel.lopez999 <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 30.0.50; Error in python-mode when try to delete a character in
 badly-indented code
Date: Mon, 11 Sep 2023 17:36:59 +0100
To reproduce from emacs -Q:
 C-x b hello.py RET
 M-x python-mode
 On the first line, type the word "return", then press the Return key.
 On the second line, type one or more spaces.
 Press Backspace. This triggers the error message:
     python-indent-line: Wrong type argument: wholenump, -4
 and, the last-typed space is not deleted.

Backtrace of the error:
 Debugger entered--Lisp error: (wrong-type-argument wholenump -4)
   indent-line-to(-4)
   python-indent-line(t)
   python-indent-dedent-line()
   python-indent-dedent-line-backspace(1)
   funcall-interactively(python-indent-dedent-line-backspace 1)
   command-execute(python-indent-dedent-line-backspace)

This can also happen with Python keywords/statements that tend to end a
scope, eg. "break" or "raise", as well as "return".

I guess the smart dedenting sees the "return" (or similar statement) at
top-level scope and then tries to move the cursor to a parent scope /
negative column that doesn't exist. Perhaps one of those indent
functions could clamp itself somehow to not do that but I'm not sure
where the best place for that would be.

Daniel



In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version
 3.24.36, cairo version 1.17.8) of 2023-02-21 built on ENO
Repository revision: 098add06eb7d742ff0e6ee0e294931a93a60c71c
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101008
System Description: Arch Linux

Configured using:
 'configure --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib
 --localstatedir=/var --mandir=/usr/share/man --with-gameuser=:games
 --with-modules --without-libotf --without-m17n-flt --without-gconf
 --with-native-compilation=yes --with-xinput2 --with-x-toolkit=gtk3
 --without-xaw3d --with-sound=no --with-tree-sitter --without-gpm
 --without-compress-install
 '--program-transform-name=s/\([ec]tags\)/\1.emacs/'
 'CFLAGS=-march=x86-64 -mtune=generic -O2 -pipe -fno-plt -fexceptions
 -Wp,-D_FORTIFY_SOURCE=2 -Wformat -fstack-clash-protection
 -fcf-protection'
 LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now'

Configured features:
ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG JSON
LCMS2 LIBSYSTEMD LIBXML2 MODULES NATIVE_COMP NOTIFY INOTIFY PDUMPER PNG
RSVG SECCOMP SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS TREE_SITTER WEBP
X11 XDBE XIM XINPUT2 XPM GTK3 ZLIB

Important settings:
  value of $LANG: en_GB.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Python

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  line-number-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message mailcap yank-media puny dired
dired-loaddefs rfc822 mml mml-sec password-cache epa derived epg rfc6068
epg-config gnus-util text-property-search time-date mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail
rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils help-fns
radix-tree cl-print debug backtrace find-func python project byte-opt
pcase treesit comint ansi-osc ring cl-loaddefs comp comp-cstr warnings
icons subr-x rx cl-seq cl-macs gv cl-extra help-mode bytecomp
byte-compile cl-lib ansi-color cus-start cus-load rmc iso-transl tooltip
cconv eldoc paren electric uniquify ediff-hook vc-hooks lisp-float-type
elisp-mode mwheel term/x-win x-win term/common-win x-dnd tool-bar dnd
fontset image regexp-opt fringe tabulated-list replace newcomment
text-mode lisp-mode prog-mode register page tab-bar menu-bar rfn-eshadow
isearch easymenu timer select scroll-bar mouse jit-lock font-lock syntax
font-core term/tty-colors frame minibuffer nadvice seq simple cl-generic
indonesian philippine cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese eucjp-ms cp51932 hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
composite emoji-zwj charscript charprop case-table epa-hook
jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button loaddefs
theme-loaddefs faces cus-face macroexp files window text-properties
overlay sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads dbusbind inotify lcms2
dynamic-setting system-font-setting font-render-setting cairo
move-toolbar gtk x-toolkit xinput2 x multi-tty make-network-process
native-compile emacs)

Memory information:
((conses 16 105838 7866)
 (symbols 48 9884 0)
 (strings 32 26714 1992)
 (string-bytes 1 822994)
 (vectors 16 18667)
 (vector-slots 8 375164 12614)
 (floats 8 37 45)
 (intervals 56 310 0)
 (buffers 984 13))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#65870; Package emacs. (Sat, 16 Sep 2023 10:07:02 GMT) Full text and rfc822 format available.

Message #8 received at 65870 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Daniel Lopez <daniel.lopez999 <at> gmail.com>, kobarity <kobarity <at> gmail.com>
Cc: 65870 <at> debbugs.gnu.org
Subject: Re: bug#65870: 30.0.50;
 Error in python-mode when try to delete a character in badly-indented
 code
Date: Sat, 16 Sep 2023 13:05:57 +0300
> Date: Mon, 11 Sep 2023 17:36:59 +0100
> From: Daniel Lopez <daniel.lopez999 <at> gmail.com>
> 
> To reproduce from emacs -Q:
>   C-x b hello.py RET
>   M-x python-mode
>   On the first line, type the word "return", then press the Return key.
>   On the second line, type one or more spaces.
>   Press Backspace. This triggers the error message:
>       python-indent-line: Wrong type argument: wholenump, -4
>   and, the last-typed space is not deleted.
> 
> Backtrace of the error:
>   Debugger entered--Lisp error: (wrong-type-argument wholenump -4)
>     indent-line-to(-4)
>     python-indent-line(t)
>     python-indent-dedent-line()
>     python-indent-dedent-line-backspace(1)
>     funcall-interactively(python-indent-dedent-line-backspace 1)
>     command-execute(python-indent-dedent-line-backspace)
> 
> This can also happen with Python keywords/statements that tend to end a
> scope, eg. "break" or "raise", as well as "return".
> 
> I guess the smart dedenting sees the "return" (or similar statement) at
> top-level scope and then tries to move the cursor to a parent scope /
> negative column that doesn't exist. Perhaps one of those indent
> functions could clamp itself somehow to not do that but I'm not sure
> where the best place for that would be.

Thanks.

kobarity, any suggestions or comments?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#65870; Package emacs. (Sat, 16 Sep 2023 15:08:02 GMT) Full text and rfc822 format available.

Message #11 received at 65870 <at> debbugs.gnu.org (full text, mbox):

From: kobarity <kobarity <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Daniel Lopez <daniel.lopez999 <at> gmail.com>, 65870 <at> debbugs.gnu.org
Subject: Re: bug#65870: 30.0.50;
 Error in python-mode when try to delete a character in badly-indented
 code
Date: Sun, 17 Sep 2023 00:06:58 +0900
[Message part 1 (text/plain, inline)]
Eli Zaretskii wrote:
> > Date: Mon, 11 Sep 2023 17:36:59 +0100
> > From: Daniel Lopez <daniel.lopez999 <at> gmail.com>
> > 
> > To reproduce from emacs -Q:
> >   C-x b hello.py RET
> >   M-x python-mode
> >   On the first line, type the word "return", then press the Return key.
> >   On the second line, type one or more spaces.
> >   Press Backspace. This triggers the error message:
> >       python-indent-line: Wrong type argument: wholenump, -4
> >   and, the last-typed space is not deleted.
> > 
> > Backtrace of the error:
> >   Debugger entered--Lisp error: (wrong-type-argument wholenump -4)
> >     indent-line-to(-4)
> >     python-indent-line(t)
> >     python-indent-dedent-line()
> >     python-indent-dedent-line-backspace(1)
> >     funcall-interactively(python-indent-dedent-line-backspace 1)
> >     command-execute(python-indent-dedent-line-backspace)
> > 
> > This can also happen with Python keywords/statements that tend to end a
> > scope, eg. "break" or "raise", as well as "return".
> > 
> > I guess the smart dedenting sees the "return" (or similar statement) at
> > top-level scope and then tries to move the cursor to a parent scope /
> > negative column that doesn't exist. Perhaps one of those indent
> > functions could clamp itself somehow to not do that but I'm not sure
> > where the best place for that would be.
> 
> Thanks.
> 
> kobarity, any suggestions or comments?

Thank you for the report.  The attached is the proposed fix.
[0001-Fix-Python-mode-error-caused-by-incorrect-indentatio.patch (application/octet-stream, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#65870; Package emacs. (Sun, 17 Sep 2023 04:07:01 GMT) Full text and rfc822 format available.

Message #14 received at 65870 <at> debbugs.gnu.org (full text, mbox):

From: Daniel Lopez <daniel.lopez999 <at> gmail.com>
To: kobarity <kobarity <at> gmail.com>, Eli Zaretskii <eliz <at> gnu.org>
Cc: 65870 <at> debbugs.gnu.org
Subject: Re: bug#65870: 30.0.50; Error in python-mode when try to delete a
 character in badly-indented code
Date: Sun, 17 Sep 2023 05:06:10 +0100
On 16/09/2023 16:06, kobarity wrote:
> 
> Eli Zaretskii wrote:
>>> Date: Mon, 11 Sep 2023 17:36:59 +0100
>>> From: Daniel Lopez <daniel.lopez999 <at> gmail.com>
>>>
>>> To reproduce from emacs -Q:
>>>    C-x b hello.py RET
>>>    M-x python-mode
>>>    On the first line, type the word "return", then press the Return key.
>>>    On the second line, type one or more spaces.
>>>    Press Backspace. This triggers the error message:
>>>        python-indent-line: Wrong type argument: wholenump, -4
>>>    and, the last-typed space is not deleted.
>>>
>>> Backtrace of the error:
>>>    Debugger entered--Lisp error: (wrong-type-argument wholenump -4)
>>>      indent-line-to(-4)
>>>      python-indent-line(t)
>>>      python-indent-dedent-line()
>>>      python-indent-dedent-line-backspace(1)
>>>      funcall-interactively(python-indent-dedent-line-backspace 1)
>>>      command-execute(python-indent-dedent-line-backspace)
>>>
>>> This can also happen with Python keywords/statements that tend to end a
>>> scope, eg. "break" or "raise", as well as "return".
>>>
>>> I guess the smart dedenting sees the "return" (or similar statement) at
>>> top-level scope and then tries to move the cursor to a parent scope /
>>> negative column that doesn't exist. Perhaps one of those indent
>>> functions could clamp itself somehow to not do that but I'm not sure
>>> where the best place for that would be.
>>
>> Thanks.
>>
>> kobarity, any suggestions or comments?
> 
> Thank you for the report.  The attached is the proposed fix.

On applying the fix to my own installation, I can confirm that it works 
for me. Thanks. :)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#65870; Package emacs. (Sun, 02 Jun 2024 21:09:02 GMT) Full text and rfc822 format available.

Message #17 received at 65870 <at> debbugs.gnu.org (full text, mbox):

From: Jakub Ječmínek <kuba <at> kubajecminek.cz>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: kobarity <kobarity <at> gmail.com>, Daniel Lopez <daniel.lopez999 <at> gmail.com>,
 65870 <at> debbugs.gnu.org
Subject: Re: bug#65870: 30.0.50;
 Error in python-mode when try to delete a character in badly-indented
 code
Date: Sun, 02 Jun 2024 21:08:30 +0000
kobarity <kobarity <at> gmail.com> writes:

> Eli Zaretskii wrote:
>> kobarity, any suggestions or comments?
>
> Thank you for the report.  The attached is the proposed fix.
>
>>From 32f0dbe5f942ffa60f0945d2ffb771db82db5832 Mon Sep 17 00:00:00 2001
> From: kobarity <kobarity <at> gmail.com>
> Date: Sat, 16 Sep 2023 23:14:45 +0900
> Subject: [PATCH] Fix Python mode error caused by incorrect indentation
>
> * lisp/progmodes/python.el (python-indent--calculate-indentation):
> Guard against negative indentation.  (Bug #65870)
>
> * test/lisp/progmodes/python-tests.el
> (python-indent-badly-indented-block-end): New test.
> ---
>  lisp/progmodes/python.el            | 2 +-
>  test/lisp/progmodes/python-tests.el | 9 +++++++++
>  2 files changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
> index 4b940b3f13b..d7e49e225d8 100644
> --- a/lisp/progmodes/python.el
> +++ b/lisp/progmodes/python.el
> @@ -1660,7 +1660,7 @@ python-indent--calculate-indentation
>          (`(:after-block-end . ,start)
>           ;; Subtract one indentation level.
>           (goto-char start)
> -         (- (current-indentation) python-indent-offset))
> +         (max 0 (- (current-indentation) python-indent-offset)))
>          (`(:at-dedenter-block-start . ,_)
>           ;; List all possible indentation levels from opening blocks.
>           (let ((opening-block-start-points
> diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el
> index a44a11896f0..f3456030975 100644
> --- a/test/lisp/progmodes/python-tests.el
> +++ b/test/lisp/progmodes/python-tests.el
> @@ -2081,6 +2081,15 @@ python-indent-after-bare-match
>     (python-tests-look-at "else:")
>     (should (= (python-indent-calculate-indentation) 4))))
>  
> +(ert-deftest python-indent-badly-indented-block-end ()
> +  "Test BUG 65870 regression."
> +  (python-tests-with-temp-buffer
> +   "
> +return
> +"
> +   (goto-char (point-max))
> +   (should (= (python-indent-calculate-indentation) 0))))
> +
>  
>  ;;; Filling

Eli, can you please install this?  I can still reproduce the original error.





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#65870; Package emacs. (Mon, 03 Jun 2024 12:11:01 GMT) Full text and rfc822 format available.

Message #20 received at 65870 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Jakub Ječmínek <kuba <at> kubajecminek.cz>
Cc: kobarity <at> gmail.com, daniel.lopez999 <at> gmail.com, 65870 <at> debbugs.gnu.org
Subject: Re: bug#65870: 30.0.50;
 Error in python-mode when try to delete a character in badly-indented
 code
Date: Mon, 03 Jun 2024 14:25:57 +0300
> Date: Sun, 02 Jun 2024 21:08:30 +0000
> From: Jakub Ječmínek <kuba <at> kubajecminek.cz>
> Cc: kobarity <kobarity <at> gmail.com>, Daniel Lopez <daniel.lopez999 <at> gmail.com>, 65870 <at> debbugs.gnu.org
> 
> kobarity <kobarity <at> gmail.com> writes:
> 
> Eli, can you please install this?  I can still reproduce the original error.

I'm waiting for other people to chime in if they want.  Please be
patient.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#65870; Package emacs. (Tue, 04 Jun 2024 05:14:01 GMT) Full text and rfc822 format available.

Message #23 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Andreas Röhler <andreas.roehler <at> easy-emacs.de>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#65870: 30.0.50; Error in python-mode when try to delete a
 character in badly-indented code
Date: Tue, 4 Jun 2024 07:12:52 +0200
Am 03.06.24 um 13:25 schrieb Eli Zaretskii:
>> Date: Sun, 02 Jun 2024 21:08:30 +0000
>> From: Jakub Ječmínek <kuba <at> kubajecminek.cz>
>> Cc: kobarity <kobarity <at> gmail.com>, Daniel Lopez <daniel.lopez999 <at> gmail.com>, 65870 <at> debbugs.gnu.org
>>
>> kobarity <kobarity <at> gmail.com> writes:
>>
>> Eli, can you please install this?  I can still reproduce the original error.
> I'm waiting for other people to chime in if they want.  Please be
> patient.
>
>
>
May reproduce a bug:

From col 4 at an empty second line, BACKSPACE  doesn't move. Instead 
sends the error:

indent-line-to: Wrong type argument: wholenump, -4 [2 times]

---

C-h k BACKSPACE:

DEL (translated from <backspace>) runs the command
python-indent-dedent-line-backspace (found in python-mode-map), which
is an interactive byte-code-function in ‘python.el’.

It is bound to DEL.

(python-indent-dedent-line-backspace ARG)

De-indent current line.
Argument ARG is passed to ‘backward-delete-char-untabify’ when
point is not in between the indentation.

---

GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.33, 
cairo version 1.16.0) of 2024-06-03





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#65870; Package emacs. (Tue, 04 Jun 2024 05:47:02 GMT) Full text and rfc822 format available.

Message #26 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Andreas Röhler <andreas.roehler <at> easy-emacs.de>
To: bug-gnu-emacs <at> gnu.org
Subject: Re: bug#65870: 30.0.50; Error in python-mode when try to delete a
 character in badly-indented code
Date: Tue, 4 Jun 2024 07:45:35 +0200
Am 03.06.24 um 13:25 schrieb Eli Zaretskii:
>> Date: Sun, 02 Jun 2024 21:08:30 +0000
>> From: Jakub Ječmínek <kuba <at> kubajecminek.cz>
>> Cc: kobarity <kobarity <at> gmail.com>, Daniel Lopez <daniel.lopez999 <at> gmail.com>, 65870 <at> debbugs.gnu.org
>>
>> kobarity <kobarity <at> gmail.com> writes:
>>
>> Eli, can you please install this?  I can still reproduce the original error.
> I'm waiting for other people to chime in if they want.  Please be
> patient.
>
>
>

patched against GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ 
Version 3.24.33, cairo version 1.16.0) of 2024-06-04

seems to work





Reply sent to Eli Zaretskii <eliz <at> gnu.org>:
You have taken responsibility. (Sat, 08 Jun 2024 12:30:02 GMT) Full text and rfc822 format available.

Notification sent to Daniel Lopez <daniel.lopez999 <at> gmail.com>:
bug acknowledged by developer. (Sat, 08 Jun 2024 12:30:02 GMT) Full text and rfc822 format available.

Message #31 received at 65870-done <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: kobarity <kobarity <at> gmail.com>
Cc: 65870-done <at> debbugs.gnu.org, daniel.lopez999 <at> gmail.com
Subject: Re: bug#65870: 30.0.50;
 Error in python-mode when try to delete a character in badly-indented
 code
Date: Sat, 08 Jun 2024 15:29:19 +0300
> Date: Sun, 17 Sep 2023 00:06:58 +0900
> From: kobarity <kobarity <at> gmail.com>
> Cc: Daniel Lopez <daniel.lopez999 <at> gmail.com>,
> 	65870 <at> debbugs.gnu.org
> 
> Eli Zaretskii wrote:
> > > Date: Mon, 11 Sep 2023 17:36:59 +0100
> > > From: Daniel Lopez <daniel.lopez999 <at> gmail.com>
> > > 
> > > To reproduce from emacs -Q:
> > >   C-x b hello.py RET
> > >   M-x python-mode
> > >   On the first line, type the word "return", then press the Return key.
> > >   On the second line, type one or more spaces.
> > >   Press Backspace. This triggers the error message:
> > >       python-indent-line: Wrong type argument: wholenump, -4
> > >   and, the last-typed space is not deleted.
> > > 
> > > Backtrace of the error:
> > >   Debugger entered--Lisp error: (wrong-type-argument wholenump -4)
> > >     indent-line-to(-4)
> > >     python-indent-line(t)
> > >     python-indent-dedent-line()
> > >     python-indent-dedent-line-backspace(1)
> > >     funcall-interactively(python-indent-dedent-line-backspace 1)
> > >     command-execute(python-indent-dedent-line-backspace)
> > > 
> > > This can also happen with Python keywords/statements that tend to end a
> > > scope, eg. "break" or "raise", as well as "return".
> > > 
> > > I guess the smart dedenting sees the "return" (or similar statement) at
> > > top-level scope and then tries to move the cursor to a parent scope /
> > > negative column that doesn't exist. Perhaps one of those indent
> > > functions could clamp itself somehow to not do that but I'm not sure
> > > where the best place for that would be.
> > 
> > Thanks.
> > 
> > kobarity, any suggestions or comments?
> 
> Thank you for the report.  The attached is the proposed fix.

Thanks, installed on the master branch, and closing the bug.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sun, 07 Jul 2024 11:24:09 GMT) Full text and rfc822 format available.

This bug report was last modified 19 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.