Skip to content

refactor type_cast_value#1852

Merged
davidism merged 1 commit into
masterfrom
validate-multi
Apr 15, 2021
Merged

refactor type_cast_value#1852
davidism merged 1 commit into
masterfrom
validate-multi

Conversation

@davidism

Copy link
Copy Markdown
Member
  • Don't need recursion to validate mutliple and nargs.
  • When validating value at runtime, only raise BadParameter, not TypeError or ValueError.
  • Validate default value against multiple and nargs in __init__. Can't use type_cast_value on default as that can have side effects such as opening a file.
  • For multiple and nargs=-1, validate that the value is iterable (and not a string). For nargs>0 validate that the length matches. For multiple and nargs>0, validate the length of each item.
  • Reword error messages for consistency.
  • Reword error message about "arity" since that's a technical term. For types.Tuple.convert, raise a BadParameter error and match the argument count error that Python would raise.
  • For ease of validation, needed to make multiple a parameter for Parameter instead of only Option. Argument checks that it's not given.

Checklist:

  • Add tests that demonstrate the correct behavior 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.

default value is validated against multiple and nargs in __init__
@davidism davidism added this to the 8.0.0 milestone Apr 15, 2021
@davidism
davidism merged commit cef43de into master Apr 15, 2021
@davidism
davidism deleted the validate-multi branch April 15, 2021 21:59
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 30, 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.

Move iterable checks from type_cast_value to __init__

1 participant