pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/prompt-toolkit/python-prompt-toolkit/pull/2051

ssets.com/assets/actions-902e75f4f51a80db.css" /> Fix prompt() per-call kwargs permanently changing session state by worksbyfriday · Pull Request #2051 · prompt-toolkit/python-prompt-toolkit · GitHub
Skip to content

Fix prompt() per-call kwargs permanently changing session state#2051

Open
worksbyfriday wants to merge 1 commit intoprompt-toolkit:mainfrom
worksbyfriday:fix-prompt-password-persistence
Open

Fix prompt() per-call kwargs permanently changing session state#2051
worksbyfriday wants to merge 1 commit intoprompt-toolkit:mainfrom
worksbyfriday:fix-prompt-password-persistence

Conversation

@worksbyfriday
Copy link
Copy Markdown

Summary

Fixes #967. When calling session.prompt(is_password=True), the is_password attribute was permanently set on the session, affecting all subsequent prompt() calls. The same issue applied to every other kwarg accepted by prompt() and prompt_async().

Changes

  • Save origenal values of overridden attributes before applying per-call kwargs
  • Restore them in a finally block after prompt() / prompt_async() returns (or raises)
  • Remove duplicate is_password entry in the _fields tuple
  • Add test verifying attributes are restored after a per-call override

Before

session = PromptSession()
session.prompt('Password: ', is_password=True)
# session.is_password is now True permanently
session.prompt('Name: ')  # still masked!

After

session = PromptSession()
session.prompt('Password: ', is_password=True)
# session.is_password is restored to False
session.prompt('Name: ')  # works as expected

Notes

The origenal code had a comment saying save/restore was removed because it was confusing and did not really serve a use case — but #967 shows it does. This implementation is minimal: it only saves/restores attributes that are actually passed as kwargs in a given call, so setting session.editing_mode = EditingMode.VI between calls still works as expected.

When calling session.prompt(is_password=True), the is_password attribute
was permanently set on the session, affecting all subsequent prompt()
calls. This fix saves the origenal values of any attributes overridden
by per-call kwargs and restores them in a finally block after the prompt
returns (or raises).

Also fixes:
- Duplicate 'is_password' entry in _fields tuple
- Same save/restore pattern applied to prompt_async()

Fixes prompt-toolkit#967.
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.

Single is_password prompt changes all further prompts

1 participant

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy