Fix prompt() per-call kwargs permanently changing session state#2051
Open
Fridayai700 wants to merge 1 commit intoprompt-toolkit:mainfrom
Open
Fix prompt() per-call kwargs permanently changing session state#2051Fridayai700 wants to merge 1 commit intoprompt-toolkit:mainfrom
Fridayai700 wants to merge 1 commit intoprompt-toolkit:mainfrom
Conversation
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 original 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #967. When calling
session.prompt(is_password=True), theis_passwordattribute was permanently set on the session, affecting all subsequentprompt()calls. The same issue applied to every other kwarg accepted byprompt()andprompt_async().Changes
finallyblock afterprompt()/prompt_async()returns (or raises)is_passwordentry in the_fieldstupleBefore
After
Notes
The original 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.VIbetween calls still works as expected.