Skip to content

Fix PromptSession validator=None reset - #2162

Open
cumminskd wants to merge 1 commit into
prompt-toolkit:mainfrom
cumminskd:polaris/fix-validator-none
Open

cumminskd wants to merge 1 commit into
prompt-toolkit:mainfrom
cumminskd:polaris/fix-validator-none

Conversation

@cumminskd

@cumminskd cumminskd commented Oct 28, 2026 •

Copy link
Copy Markdown

Summary

PromptSession.prompt() and prompt_async() currently treat an omitted validator argument and an explicit validator=None the same way. As a result, a validator configured on a reusable session cannot be cleared for a later prompt.

This change distinguishes those two call forms:

  • Omitting validator preserves the session validator.
  • Passing validator=None clears the session validator.
  • Passing another validator replaces it.

The behavior is implemented for both synchronous and asynchronous prompts, with regression coverage in tests/test_cli.py and updated API documentation.

Fixes #2159

Verification

  • Focused CLI tests: 37 passed
  • Full test suite: 159 passed
  • Ruff: passed
  • Mypy: passed across 145 source files
  • A pre-fix probe reproduced the original explicit-None failure
  • Omitted-validator preservation and non-None replacement were also verified for sync and async prompts

Related work

PR #2161 is acknowledged as a documentation-based alternative. It documents the existing workaround and tutorial guidance without changing runtime behavior. This PR addresses the underlying runtime behavior requested in #2159.

Backwards-compatibility consideration

This intentionally changes the meaning of an explicit validator=None passed to prompt() or prompt_async(): it now clears the session validator. Code that previously relied on None leaving an existing validator active should omit the argument instead. Calls that omit validator, pass a validator, or use the existing completer and auto-suggest behavior retain their prior semantics.

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.

PromptSession.prompt() ignores validator=None

1 participant