Skip to content

Explicitly require Y/N for Command._ask #244

@AlvinRamoutar

Description

@AlvinRamoutar

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] yhn

Expected 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

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions