Skip to main content
Version: 0.5.4

common.validation

validate_dict

def validate_dict(spec: Type[_TypedDict],
doc: StrAny,
path: str,
filter_f: TFilterFunc = None,
validator_f: TCustomValidator = None) -> None

[view_source]

Validate the doc dictionary based on the given typed dictionary specification spec.

Arguments:

  • spec Type[_TypedDict] - The typed dictionary that doc should conform to.
  • doc StrAny - The dictionary to validate.
  • path str - The string representing the location of the dictionary in a hierarchical data structure.
  • filter_f TFilterFunc, optional - A function to filter keys in doc. It should return True for keys to be kept. Defaults to a function that keeps all keys.
  • validator_f TCustomValidator, optional - A function to perform additional validation for types not covered by this function. It should return True if the validation passes or raise DictValidationException on validation error. For types it cannot validate, it should return False to allow chaining. Defaults to a function that rejects all such types.

Raises:

  • DictValidationException - If there are missing required fields, unexpected fields, type mismatches or unvalidated types in doc compared to spec.

Returns:

None

This demo works on codespaces. Codespaces is a development environment available for free to anyone with a Github account. You'll be asked to fork the demo repository and from there the README guides you with further steps.
The demo uses the Continue VSCode extension.

Off to codespaces!

DHelp

Ask a question

Welcome to "Codex Central", your next-gen help center, driven by OpenAI's GPT-4 model. It's more than just a forum or a FAQ hub – it's a dynamic knowledge base where coders can find AI-assisted solutions to their pressing problems. With GPT-4's powerful comprehension and predictive abilities, Codex Central provides instantaneous issue resolution, insightful debugging, and personalized guidance. Get your code running smoothly with the unparalleled support at Codex Central - coding help reimagined with AI prowess.