-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
create free standing functions to match model methods #5213
Comments
Perhaps we should splits it up in a multiple modules which can have more specific names? Like 'serialization' and 'validation'? imo something like, would have more clarity for me from .model import construct
from .serialization import dump, dump_json, validate
from .validation import validate, validate_json Compared to something like this from .util import construct, dump, dump_json_bytes, validate, validate_json But if you're not looking to split it up, the common theme i notice is |
I will say — I don't think I like I think |
I think I think all functions should either take a type or an instance of model or dataclass. |
My concern with naming it |
yes, because we would document that. I think Need to also have:
|
Is this still wanted? @samuelcolvin |
I think there's a chance we might still want this, especially if we end up with |
BaseModel
methodsValidator
methods V2: Thevalidate
general method #4669BareModel
model_
prefix from the free standing functionsdump_json_bytes
Incomplete list of functions:
validate(type[T], data: any) -> T
validate_json(type[T], data: str | bytes) -> T
construct(type[T], data) -> T
dump -> any
dump_json -> str
dump_json_bytes -> bytes
json_schema -> dict
json_schema_json -> bytes
These should work on models,
BareModel
, dataclasses, and instrances of Validator (#4669).Name ideas for this module:
standalone
,methods
(technically they're the opposite),free
???The text was updated successfully, but these errors were encountered: