Skip to content

Ensure confirm() returns a boolean after Enter#2077

Open
zhangli091011 wants to merge 3 commits into
prompt-toolkit:mainfrom
zhangli091011:fix/issue-2046-confirm-bool
Open

Ensure confirm() returns a boolean after Enter#2077
zhangli091011 wants to merge 3 commits into
prompt-toolkit:mainfrom
zhangli091011:fix/issue-2046-confirm-bool

Conversation

@zhangli091011

@zhangli091011 zhangli091011 commented Jul 19, 2026

Copy link
Copy Markdown

Summary

Fix prompt_toolkit.shortcuts.confirm() returning an empty string when Enter is pressed without selecting an answer.

Enter previously fell through to PromptSession's normal accept binding, which returned the empty buffer contents. The confirmation session now handles Enter explicitly and continues waiting for y or n, so successful results remain True or False.

The CI environment's current mypy/typeshed versions also exposed an incompatible return annotation in the existing custom PDB trace dispatcher. Its internal return annotation is now Any, matching the range of values accepted by the debugger API without changing runtime behavior.

Fixes #2046.

Tests

  • Added regression coverage for Enter followed by y, Y, n, and N
  • .venv\Scripts\python.exe -m pytest tests/test_shortcuts.py -q -k confirm
  • ruff check src/prompt_toolkit/shortcuts/prompt.py tests/test_shortcuts.py
  • ruff format --check src/prompt_toolkit/shortcuts/prompt.py tests/test_shortcuts.py
  • Strict mypy check for the changed implementation
  • typos .

AI disclosure

OpenCode using myself/gpt-5.6-sol assisted with issue investigation, implementation, and test preparation. I reviewed the change and verification results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

prompt_toolkit.shortcuts.confirm doesn't always return bool

1 participant