Skip to content

Commit 07abfcf

Browse files
authored
Make debugger work with Python 3.14 (#15085)
A Linux user reported in spyder-ide/spyder#25299 that our debugger is failing with their distro packages for Python 3.14 due to an error in IPython 8 (the error is not present in version 9). After some digging, I applied the minimal changes I could from commit a796b95 to fix that. I also checked that the debugger is working fine for Python 3.11 to 3.13.
2 parents fed55e3 + 7f159ef commit 07abfcf

File tree

1 file changed

+10
-32
lines changed

1 file changed

+10
-32
lines changed

IPython/core/debugger.py

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,7 @@ def __init__(self, completekey=None, stdin=None, stdout=None, context=5, **kwarg
248248
docs for more info.
249249
"""
250250

251-
# Parent constructor:
252-
try:
253-
self.context = int(context)
254-
if self.context <= 0:
255-
raise ValueError("Context must be a positive integer")
256-
except (TypeError, ValueError) as e:
257-
raise ValueError("Context must be a positive integer") from e
251+
self.context = int(context)
258252

259253
# `kwargs` ensures full compatibility with stdlib's `pdb.Pdb`.
260254
OldPdb.__init__(self, completekey, stdin, stdout, **kwargs)
@@ -490,14 +484,9 @@ def print_stack_trace(self, context=None):
490484
ColorsNormal = Colors.Normal
491485
if context is None:
492486
context = self.context
493-
try:
494-
context = int(context)
495-
if context <= 0:
496-
raise ValueError("Context must be a positive integer")
497-
except (TypeError, ValueError) as e:
498-
raise ValueError("Context must be a positive integer") from e
499487
try:
500488
skipped = 0
489+
to_print = ""
501490
for hidden, frame_lineno in zip(self.hidden_frames(self.stack), self.stack):
502491
if hidden and self.skip_hidden:
503492
skipped += 1
@@ -507,31 +496,21 @@ def print_stack_trace(self, context=None):
507496
f"{Colors.excName} [... skipping {skipped} hidden frame(s)]{ColorsNormal}\n"
508497
)
509498
skipped = 0
510-
self.print_stack_entry(frame_lineno, context=context)
499+
to_print += self.format_stack_entry(frame_lineno)
511500
if skipped:
512-
print(
501+
to_print += (
513502
f"{Colors.excName} [... skipping {skipped} hidden frame(s)]{ColorsNormal}\n"
514503
)
504+
print(to_print, file=self.stdout)
515505
except KeyboardInterrupt:
516506
pass
517507

518-
def print_stack_entry(self, frame_lineno, prompt_prefix='\n-> ',
519-
context=None):
520-
if context is None:
521-
context = self.context
522-
try:
523-
context = int(context)
524-
if context <= 0:
525-
raise ValueError("Context must be a positive integer")
526-
except (TypeError, ValueError) as e:
527-
raise ValueError("Context must be a positive integer") from e
528-
print(self.format_stack_entry(frame_lineno, '', context), file=self.stdout)
508+
def print_stack_entry(self, frame_lineno, prompt_prefix='\n-> '):
509+
print(self.format_stack_entry(frame_lineno, ''), file=self.stdout)
529510

530-
# vds: >>
531511
frame, lineno = frame_lineno
532512
filename = frame.f_code.co_filename
533513
self.shell.hooks.synchronize_with_editor(filename, lineno, 0)
534-
# vds: <<
535514

536515
def _get_frame_locals(self, frame):
537516
""" "
@@ -555,15 +534,14 @@ def _get_frame_locals(self, frame):
555534
else:
556535
return frame.f_locals
557536

558-
def format_stack_entry(self, frame_lineno, lprefix=': ', context=None):
559-
if context is None:
560-
context = self.context
537+
def format_stack_entry(self, frame_lineno, lprefix=': '):
538+
context = self.context
561539
try:
562540
context = int(context)
563541
if context <= 0:
564542
print("Context must be a positive integer", file=self.stdout)
565543
except (TypeError, ValueError):
566-
print("Context must be a positive integer", file=self.stdout)
544+
print("Context must be a positive integer", file=self.stdout)
567545

568546
import reprlib
569547

0 commit comments

Comments
 (0)