![]() The additional metadata is ignored and the root type is used. TheĪnnotated hint may contain a single call to the Field function, but otherwise See typing.Deque below for sub-type constraints datetime.date see Datetime Types below for more detail on parsing and validation datetime.time see Datetime Types below for more detail on parsing and validation datetime.datetime see Datetime Types below for more detail on parsing and validation datetime.timedelta see Datetime Types below for more detail on parsing and validation typing.Any allows any value including None, thus an Any field is optional typing.Annotated allows wrapping another type with arbitrary metadata, as per PEP-593. ![]() See typing.FrozenSet below for sub-type constraints deque allows list, tuple, set, frozenset, deque, or generators and casts to a deque See typing.Set below for sub-type constraints frozenset allows list, tuple, set, frozenset, deque, or generators and casts to a frozen set See typing.Dict below for sub-type constraints set allows list, tuple, set, frozenset, deque, or generators and casts to a set See typing.Tuple below for sub-type constraints dict dict(v) is used to attempt to convert a dictionary See typing.List below for sub-type constraints tuple allows list, tuple, set, frozenset, deque, or generators and casts to a tuple See this warning on loss of information during data conversion float similarly, float(v) is used to coerce values to floats str strings are accepted as-is, int float and Decimal are coerced using str(v), bytes and bytearray areĬonverted using v.decode(), enums inheriting from str are converted using v.value,Īnd all other types cause an error bytes bytes are accepted as-is, bytearray is converted using bytes(v), str are converted using v.encode(),Īnd int, float, and Decimal are coerced using str(v).encode() list allows list, tuple, set, frozenset, deque, or generators and casts to a list None, type(None) or Literal (equivalent according to PEP 484) allows only None value bool see Booleans below for details on how bools are validated and what values are permitted int pydantic uses int(v) to coerce types to an int to require a positive int) seeĬonstrained Types. Strict Types if you need to constrain the values allowed (e.g. Pydantic supports many common types from the Python standard library. If no existing type suits your purpose you can also implement your own pydantic-compatible types So pydantic implements many commonly used types. For many useful applications, however, no standard library type exists, ![]() Where possible pydantic uses standard library types to define fields, thus smoothing
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |