Subject: bug#65870: 30.0.50; Error in python-mode when try to delete a character in badly-indented code

From: Daniel Lopez <[email-masked]>
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))