Repository navigation
Explicitly require Y/N for Command._ask #244
Description
Is your feature request related to a problem? Please describe.
Had pymanager uninstall <tag> in my terminal and in a dumb panic on my split keyboard, submitted the characters yhn:
pymanager uninstall 3.13.11
Uninstall Python 3.13.11? [Y/n] yhnExpected to cancel/break since yhn does not match a provided option - y or n.
In actuality, it proceeded to remove that python installation.
Describe the solution you'd like
Literally match for the submitted character y or n.
Describe alternatives you've considered
Not panicking and hitting n (or hitting anything else really, as long as it does not start with y)
Additional context
Was a silly mistake that costed me enough rebuild time that I came back just to figure out why it happened.
https://github.com/python/pymanager/blob/main/src/manage/commands.py#L624
pymanager/src/manage/commands.py
Lines 610 to 624 in 682d0f8
| def _ask(self, fmt, *args, yn_text="Y/n", expect_char="y"): | |
| if not self.confirm: | |
| return True | |
| if not LOGGER.would_print(): | |
| LOGGER.warn("Cannot prompt for confirmation at this logging level. " | |
| "Pass --yes to accept the default response.") | |
| if not LOGGER.would_log_to_console(logging.WARN): | |
| sys.exit(1) | |
| return False | |
| LOGGER.print(f"{fmt} [{yn_text}] ", *args, end="") | |
| try: | |
| resp = input().casefold() | |
| except Exception: | |
| return False | |
| return not resp or resp.startswith(expect_char.casefold()) |
Since we match via startswith, it does not matter what the remaining characters are - as long as expect_char is the first char, then _ask evaluates.
Activity
pythonGH-244 explicitly require Y/N for Command._ask
AlvinRamoutar commentedon Dec 31, 2025
I opened #245 for this - understandably its such a small issue that I'm alright if this gets closed.
Nonetheless, thanks for the Windows support :)
zooba commentedon Jan 14, 2026
I'm interested why you expect typing "yes" to cancel (I know that's not your example, but that's the effect of the proposed change).
In general, I'm opposed to changes that enforce arbitrary limitations on the user experience - allowing any response and matching the first character was intentional.
But if there's a solid reason to do it, I could be convinced. "I panicked and typed
ynh" is close enough to "I panicked and typedy" that I don't think we meaningfully solve the panic issue with this change (panicking and pressing Ctrl+C should abort).