v1.7
版本发布时间: 2020-10-26 20:02:36
pydantic/pydantic最新发布版本:v2.9.2(2024-09-17 22:59:21)
See Changelog.
Thank you to pydantic's sponsors: @timdrijvers, @BCarley, @chdsbd, @tiangolo, @matin, @linusg, @kevinalh, @jorgecarleitao, @koxudaxi, @primer-api for their kind support.
Highlights
- python 3.9 support, thanks @PrettyWood
- Private model attributes, thanks @MrMrRobat
-
"secrets files" support in
BaseSettings
, thanks @mdgilene - convert stdlib dataclasses to pydantic dataclasses and use stdlib dataclasses in models, thanks @PrettyWood
Changes
-
Breaking Change: remove
__field_defaults__
, adddefault_factory
support withBaseModel.construct
. Use.get_default()
method on fields in__fields__
attribute instead, #1732 by @PrettyWood - Rearrange CI to run linting as a separate job, split install recipes for different tasks, #2020 by @samuelcolvin
- Allows subclasses of generic models to make some, or all, of the superclass's type parameters concrete, while also defining new type parameters in the subclass, #2005 by @choogeboom
- Call validator with the correct
values
parameter type inBaseModel.__setattr__
, whenvalidate_assignment = True
in model config, #1999 by @me-ransh - Force
fields.Undefined
to be a singleton object, fixing inherited generic model schemas, #1981 by @daviskirk - Include tests in source distributions, #1976 by @sbraz
- Add ability to use
min_length/max_length
constraints with secret types, #1974 by @uriyyo - Also check
root_validators
whenvalidate_assignment
is on, #1971 by @PrettyWood - Fix const validators not running when custom validators are present, #1957 by @hmvp
- add
deque
to field types, #1935 by @wozniakty - add basic support for python 3.9, #1832 by @PrettyWood
- Fix typo in the anchor of exporting_models.md#modelcopy and incorrect description, #1821 by @KimMachineGun
- Added ability for
BaseSettings
to read "secret files", #1820 by @mdgilene - add
parse_raw_as
utility function, #1812 by @PrettyWood - Support home directory relative paths for
dotenv
files (e.g.~/.env
), #1803 by @PrettyWood - Clarify documentation for
parse_file
to show that the argument should be a file path not a file-like object, #1794 by @mdavis-xyz - Fix false positive from mypy plugin when a class nested within a
BaseModel
is namedModel
, #1770 by @selimb - add basic support of Pattern type in schema generation, #1767 by @PrettyWood
- Support custom title, description and default in schema of enums, #1748 by @PrettyWood
- Properly represent
Literal
Enums whenuse_enum_values
is True, #1747 by @noelevans - Allows timezone information to be added to strings to be formatted as time objects. Permitted formats are
Z
for UTC or an offset for absolute positive or negative time shifts. Or the timezone data can be omitted, #1744 by @noelevans - Add stub
__init__
with python 3.6 signature forForwardRef
, #1738 by @sirtelemak - Fix behaviour with forward refs and optional fields in nested models, #1736 by @PrettyWood
- add
Enum
andIntEnum
as valid types for fields, #1735 by @PrettyWood - Change default value of
__module__
argument ofcreate_model
fromNone
to'pydantic.main'
. Set reference of created concrete model to it's module to allow pickling (not applied to models created in functions), #1686 by @MrMrRobat - Add private attributes support, #1679 by @MrMrRobat
- add
config
to@validate_arguments
, #1663 by @samuelcolvin - Allow descendant Settings models to override env variable names for the fields defined in parent Settings models with
env
in theirConfig
. Previously onlyenv_prefix
configuration option was applicable, #1561 by @ojomio - Support
ref_template
when creating schema$ref
s, #1479 by @kilo59 - Add a
__call__
stub toPyObject
so that mypy will know that it is callable, #1352 by @brianmaissy -
pydantic.dataclasses.dataclass
decorator now supports built-indataclasses.dataclass
. It is hence possible to convert an existingdataclass
easily to add pydantic validation. Moreover nested dataclasses are also supported, #744 by @PrettyWood