GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix rendering when `prompt_suffix` is empty by gene1wood · Pull Request #3021 · pallets/click

Conversation

@gene1wood

@gene1wood gene1wood commented Jul 28, 2025

Copy link
Copy Markdown
Contributor

This changes the implementation of the fixes in #1836 and #2093 to address the problem that they created when click.prompt or click.confirm has a prompt_suffix value which is empty.

This still fixes the problems reported in #665 and #2092 but does so without modifying the prompt and adding a trailing space.

Previously, the problem was solved by trimming all trailing space characters from the prompt and then adding a single trailing space to every prompt. This was only visible if the last character in the prompt wasn't a space character. In those cases a prompt like "This is my prompt" would render as "This is my prompt ". Additionally, in the previous solution, if the err=True argument was passed, that final trailing space character that was added would be sent to STDOUT while the rest of the prompt would go to STDERR. This also wasn't very apparent since it was a space character.

This different implementation uses the last character of the prompt to work around #665 and #2092 instead of adding a space character. This fixes most of the potentially confusing behavior. It does retain one confusing behavior which is described above, where if you use err=True the last character of the prompt is sent to STDOUT instead of STDERR. Previously, this last character sent to STDOUT would always be a space character. Now if the last character of the prompt is not a space character, that final character will go to STDOUT.

For example if you call

click.prompt("bar", prompt_suffix="", err=True)

The ba will go to STDERR and the r will go to STDOUT. Previously bar would go to STDERR and an added would go to STDOUT.

This odd behavior, which is already present but just applies to a space character, is worth accepting so that the prompt_suffix correctly renders the suffix as it did in version 7.1.2 and prior.

This also adds unit tests for cases where prompt_suffix is empty.

This fixes #3019

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
gene1wood added 2 commits July 28, 2025 16:56
@gene1wood
Fix rendering when prompt_suffix is empty
812b800
This changes the implementation of the fixes in pallets#1836 and pallets#2093 to address
the problem that they created when `click.prompt` or `click.confirm` has a
`prompt_suffix` value which is empty.

This still fixes the problems reported in pallets#665 and pallets#2092 but does so without
modifying the prompt and adding a trailing space.

Previously, the problem was solved by trimming all trailing space characters
from the prompt and then adding a single trailing space to every prompt.
This was only visible if the last character in the prompt wasn't a space
character. In those cases a prompt like "This is my prompt" would render
as "This is my prompt ". Additionally, in the previous solution, if the
`err=True` argument was passed, that final trailing space character that
was added would be sent to STDOUT while the rest of the prompt would go
to STDERR. This also wasn't very apparent since it was a space character.

This different implementation uses the last character of the prompt to
work around pallets#665 and pallets#2092 instead of adding a space character. This fixes
most of the potentially confusing behavior. It does retain one confusing
behavior which is described above, where if you use `err=True` the last
character of the prompt is sent to STDOUT instead of STDERR. Previously,
this last character sent to STDOUT would always be a space character.
Now if the last character of the prompt is not a space character, that final
character will go to STDOUT.

For example if you call

```python
click.prompt("bar", prompt_suffix="", err=True)
```

The `ba` will go to STDERR and the `r` will go to STDOUT.
Previously `bar` would go to STDERR and an added ` ` would go to STDOUT.

This odd behavior, which is already present but just applies to a space
character, is worth accepting so that the `prompt_suffix` correctly renders
the suffix as it did in version 7.1.2 and prior.

This also adds unit tests for cases where `prompt_suffix` is empty.

This fixes pallets#3019
@gene1wood
Merge branch 'main' into fix_prompt_suffix
2608132
@Rowlando13
Rowlando13 requested a review from kdeldycke September 24, 2025 03:11
@Rowlando13 Rowlando13 added this to the 8.3.1 milestone Sep 24, 2025
@Rowlando13 Rowlando13 added the bug label Sep 24, 2025
@kdeldycke kdeldycke added the prompt Interactive input and confirmation label Sep 25, 2025
@kdeldycke

kdeldycke commented Sep 25, 2025

Copy link
Copy Markdown
Collaborator

I agree with you that having the last character of the prompt being sent to <stdout> instead of <stderr> is confusing.

But your PR has the merit of:

  • making the behavior more deterministic
  • not hiding the edge-case visually by resorting to spaces
  • adding unit-tests on cases that were not covered before

For me this is a case of "worse is better", in which we gradually tends to the ideal behavior. The ideal behavior being a refactor of the prompt() / confirm() methods.

I am in favor of merging it in stable for a Click 8.3.1 release.

But before that, could you:

  • add a .. versionchanged:: 8.3.1 item in the docstring of each function to explain the change in behavior,
  • add a changelog entry to CHANGES.rst,
  • and change the branch target from main to stable please?
gene1wood reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gene1wood
gene1wood changed the base branch from main to stable September 25, 2025 15:41
gene1wood added 3 commits September 25, 2025 08:47
@gene1wood
Merge branch 'stable' into fix_prompt_suffix
1bfdb91
@gene1wood
Add details to prompt and confirm docstrings regarding 8.3.1 change
1c9fc6d
This adds details of the change in pallets#3021
@gene1wood
Add note to CHANGES.rst about pallets#3021
20df0b3
@gene1wood

gene1wood commented Sep 25, 2025

Copy link
Copy Markdown
Contributor Author

@kdeldycke Sure thing

I've

  • Re-added the note to CHANGES.rst
  • Changed the PR to be based off of stable
  • Updated docstrings for confirm and prompt
    • Note : I tried to find a sweet spot between too verbose and too succinct with the docstring additions. If you'd like to see more or less detail let me know and I can tweak them.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

davidism
davidism reviewed Sep 25, 2025
View reviewed changes
Comment thread src/click/termui.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@gene1wood
Shorten the docstring annotations for confirm and prompt
27de74a
kdeldycke
kdeldycke approved these changes Sep 26, 2025
View reviewed changes
@Rowlando13
Rowlando13 merged commit 8533c96 into pallets:stable Oct 2, 2025
@gene1wood
gene1wood deleted the fix_prompt_suffix branch October 2, 2025 05:58
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Oct 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@davidism davidism davidism left review comments
@kdeldycke kdeldycke kdeldycke approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

prompt Interactive input and confirmation

Projects

None yet

Milestone

8.3.1

Development

Successfully merging this pull request may close these issues.

click.prompt and click.confirm argument prompt_suffix no longer works when suffix is empty

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@gene1wood @kdeldycke @davidism @Rowlando13
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.