Skip to content

Conversation

@Sevrain1
Copy link

@Sevrain1 Sevrain1 commented Dec 20, 2025

This commit addresses the issue of the keyboard interrupt message always printing, even in cases where it's not needed and is explicitly set to an empty string. This allows users to disable/replace said print when needed, while avoiding the redundant newline that's currently being printed when kbi_msg="".

(The commit also introduces the usage of TYPE_CHECKING to improve performance in the changed modules).

What is the problem that this PR addresses?

When kbi_msg="" and a KeyboardInterrupt is encountered, the program still calls the prompt's inner print() , and needlessly prints nothing while adding a redundant newline.
There is essentially no way for the user to disable the kbi_msg and its newline print, even when it's not needed and is breaking the design of the user's program.

...

How did you solve it?

I've added None an optional argument to kbi_msg.
If the user passes any string (even an empty one), it is printed along with a newline.
If the user passes in None, no text or newline will be printed.
This is fully backwards compatible with the current behaviour of kbi_msg, and simply allows users to pass in None to disable this unneeded print.

...

Checklist

  • [ x] I have read the Contributor's Guide.
  • [ x] I will check that all automated PR checks pass before the PR gets reviewed.

This commit addresses the issue of the keyboard interrupt message always printing,
even in cases where it's not needed and is explicitly set to an empty string.
This allows users to disable/replace said print when needed, while avoiding the redundant
newline that's currenly being printed when `kbi_msg=""`.

This commit also introduces the usage of `TYPE_CHECKING` to improve performance
in the changed modules.
@Sevrain1
Copy link
Author

Hi @tmbo,
Could you please review the PR and (if it's acceptable), approve the workflow run?

Thank you.

Copy link
Collaborator

@kiancross kiancross left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @Sevrain1 - this fix looks good. Would you be able to add a unit test?

It's probably best to put any TYPE_CHECKING changes in another PR to keep this scoped to a single issue.

@Sevrain1
Copy link
Author

@kiancross,
Unit tests added and previous typing imports restored.
Please review when you have time.

Thanks.

This commit adds tests to the `Form` `Prompt` and `Question` classes
to ensure no message is printed when a KeyboardInterrupt is raised
during an `ask()`/`ask_async()` call where `kbi_msg=None`.
@Sevrain1
Copy link
Author

@kiancross,
The Python 3.9 instances are failing since late 2024 in all PRs due to e401e8a introducing a Path | str type hint, which isn't supported in Python versions < 3.10.
Since Python 3.9 is already EOL, I think you should consider removing support for it in upcoming versions. Otherwise, I can fix the bug.

Also, I think the black/isort/flake checks can all be replaced by (the much faster) ruff check / ruff format.
poetry can also be replaced by the much simpler and faster uv tool.

@kiancross
Copy link
Collaborator

kiancross commented Dec 30, 2025

I was just working on the broken CI when you posted your comment. I've removed support for Python 3.9 in #472, and also fixed an issue with the docs build breaking.

Also, I think the black/isort/flake checks can all be replaced by (the much faster) ruff check / ruff format.
poetry can also be replaced by the much simpler and faster uv tool.

Worth creating an issue for this if you think it's something to be persued. Then others e.g., @tmbo can offer thoughts.

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.

2 participants