Skip to content

Option callbacks are now invoked inside prompt and can be used to validate prompt inputs#1785

Merged
davidism merged 1 commit into
pallets:masterfrom
MLH-Fellowship:sanitize-input
Feb 24, 2021
Merged

Option callbacks are now invoked inside prompt and can be used to validate prompt inputs#1785
davidism merged 1 commit into
pallets:masterfrom
MLH-Fellowship:sanitize-input

Conversation

@Saif807380

@Saif807380 Saif807380 commented Feb 16, 2021

Copy link
Copy Markdown
Contributor

Callbacks used to be invoked for the prompt results, therefore couldn't be used as validators for validating prompt input. Following are the changes made -

  • Inlined Parameter.process_value into Parameter.full_process_value
  • Renamed full_process_value to process_value
  • Moved the if self.callback block from handle_parse_result to the bottom process_value

The current behaviour due to the above changes is as expected to be. The user will be prompted until he/she enters a value deemed valid by the validator callback.

However, this test is failing. From what I understand, process_value gets the value from the prompt when value is None and self.prompt is True. I think that self.prompt_required needs to be used somewhere but I'm not sure where exactly.

I plan to update the docs, once all tests pass.

Checklist:

  • Add tests that demonstrate the correct behaviour of the change. Tests should fail without the change.
  • Add or update relevant docs, in the docs folder and in code.
  • Add an entry in CHANGES.rst summarizing the change and linking to the issue.
  • Add .. versionchanged:: entries in any relevant code docs.
  • Run pre-commit hooks and fix any issues.
  • Run pytest and tox, no tests failed.

Comment thread src/click/core.py Outdated
@davidism davidism added this to the 8.0.0 milestone Feb 24, 2021
@davidism
davidism merged commit 80086c4 into pallets:master Feb 24, 2021
@davidism
davidism deleted the sanitize-input branch February 24, 2021 22:42
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Mar 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sanitization for click inputs

2 participants