You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using BaseModel.model_validate_json() or BaseModel.model_validate() the optional parameter "context" is typed to be a dict[str, Any].
This context is made available to validators via the ValidationInfo object.
The type of the info.context object is "Any | None" instead of "dict[str,Any] | None".
Example Code
fromtypingimportAnyfrompydanticimportBaseModel, model_validatorfrompydantic_core.core_schemaimportValidationInfoclassModel(BaseModel):
@model_validator(mode="after")defvalidator(self, info: ValidationInfo) ->Any:
info.context# this returns a object of type "Any | None"Model.model_validate_json("{}", context={}) # type of context has to be "dict[str, Any] | None"
Indeed, looks like our type hints could be improved. Would you be interested in opening a PR to fix this issue? Thanks for bringing it to our attention!
Initial Checks
Description
When using BaseModel.model_validate_json() or BaseModel.model_validate() the optional parameter "context" is typed to be a dict[str, Any].
This context is made available to validators via the ValidationInfo object.
The type of the info.context object is "Any | None" instead of "dict[str,Any] | None".
Example Code
Python, Pydantic & OS Version
The text was updated successfully, but these errors were encountered: