TurboGears / TurboGears/backlash

Interactive debugger console crashes on incomplete or multi-line input

Open
#30 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
13
Forks
13
PR merge metrics
No merged PRs in 30d

Description

Goal

Make the interactive debugger console handle incomplete input instead of
raising.

Done when: evaluating an incomplete statement (for example if True:) in the
debugger console produces a sensible continuation/error response rather than an
exception, on every supported Python version, and a test covers it.

Reproduction:

from backlash.console import Console
Console({}, {}, None).eval('if True:')

Current behaviour, reproduced on Python 3.9, 3.13 and 3.14 alike:

AttributeError: 'NoneType' object has no attribute 'co_consts'

Cause: _wrap_compiler wraps console.compile and unconditionally calls
console.loader.register(code, source) with the result. For incomplete input,
codeop legitimately returns None to signal "needs more input", and
_ConsoleLoader.register then dereferences code.co_consts.

A guard for code is None in the wrapper (or in register) appears to be the
smallest fix, but the "needs more input" case then also has to be represented
in the console response.

Why

This is not version-specific: it affects every supported Python, so it is a
long-standing break rather than a recent regression. Any multi-line input in
the in-browser console (if, for, def, try, ...) raises instead of being
handled, which makes the console unusable for anything beyond single
expressions.

No test currently covers this path.

References

  • backlash/console.py (_wrap_compiler, _ConsoleLoader.register, _InteractiveConsole.runsource)
  • stdlib codeop "needs more input" contract (compile_command returning None)
  • tests/test_console.py may be a natural home for a regression test

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in backlash/console.py by tracing _wrap_compiler, _ConsoleLoader.register, and _InteractiveConsole.runsource, then inspect the stdlib codeop contract for compile_command returning None. Add a regression test in tests/test_console.py for incomplete input and run the console tests across supported Python versions. Done means incomplete and multi-line input receives a continuation or error response without raising.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.