v1.10.0
版本发布时间: 2022-08-30 23:55:09
pydantic/pydantic最新发布版本:v2.9.2(2024-09-17 22:59:21)
See #4419 for feedback and discussion, docs are live at pydantic-docs.helpmanual.io.
- Refactor the whole pydantic
dataclass
decorator to really act like its standard lib equivalent. It hence keeps__eq__
,__hash__
, ... and makes comparison with its non-validated version possible. It also fixes usage offrozen
dataclasses in fields and usage ofdefault_factory
in nested dataclasses. The support ofConfig.extra
has been added. Finally, config customization directly via adict
is now possible, #2557 by @PrettyWood
BREAKING CHANGES:- The
compiled
boolean (whether pydantic is compiled with cython) has been moved frommain.py
toversion.py
- Now that
Config.extra
is supported,dataclass
ignores by default extra arguments (likeBaseModel
)
- The
- Fix PEP487
__set_name__
protocol inBaseModel
for PrivateAttrs, #4407 by @tlambert03 - Allow for custom parsing of environment variables via
parse_env_var
inConfig
, #4406 by @acmiyaguchi - Rename
master
tomain
, #4405 by @hramezani - Fix
StrictStr
does not raiseValidationError
whenmax_length
is present inField
, #4388 by @hramezani - Make
SecretStr
andSecretBytes
hashable, #4387 by @chbndrhnns - Fix
StrictBytes
does not raiseValidationError
whenmax_length
is present inField
, #4380 by @JeanArhancet - Add support for bare
type
, #4375 by @hramezani - Support Python 3.11, including binaries for 3.11 in PyPI, #4374 by @samuelcolvin
- Add support for
re.Pattern
, #4366 by @hramezani - Fix
__post_init_post_parse__
is incorrectly passed keyword arguments when no__post_init__
is defined, #4361 by @hramezani - Fix implicitly importing
ForwardRef
andCallable
frompydantic.typing
instead oftyping
and also exposeMappingIntStrAny
, #4358 by @aminalaee - remove
Any
types from thedataclass
decorator so it can be used with thedisallow_any_expr
mypy option, #4356 by @DetachHead - moved repo to
pydantic/pydantic
, #4348 by @yezz123 - fix "extra fields not permitted" error when dataclass with
Extra.forbid
is validated multiple times, #4343 by @detachhead - Add Python 3.9 and 3.10 examples to docs, #4339 by @Bobronium
- Discriminated union models now use
oneOf
instead ofanyOf
when generating OpenAPI schema definitions, #4335 by @MaxwellPayne - Allow type checkers to infer inner type of
Json
type.Json[list[str]]
will be now inferred aslist[str]
,Json[Any]
should be used instead of plainJson
. Runtime behaviour is not changed, #4332 by @Bobronium - Allow empty string aliases by using a
alias is not None
check, rather thanbool(alias)
, #4253 by @sergeytsaplin - Update
ForwardRef
s inField.outer_type_
, #4249 by @JacobHayes - The use of
__dataclass_transform__
has been replaced bytyping_extensions.dataclass_transform
, which is the preferred way to mark pydantic models as a dataclass under PEP 681, #4241 by @multimeric - Use parent model's
Config
when validating nestedNamedTuple
fields, #4219 by @synek - Update
BaseModel.construct
to work with aliased Fields, #4192 by @kylebamos - Catch certain raised errors in
smart_deepcopy
and revert todeepcopy
if so, #4184 by @coneybeare - Add
Config.anystr_upper
andto_upper
kwarg to constr and conbytes, #4165 by @satheler - Fix JSON schema for
set
andfrozenset
when they include default values, #4155 by @aminalaee - Teach the mypy plugin that methods decorated by
@validator
are classmethods, #4102 by @DMRobertson - Improve mypy plugin's ability to detect required fields, #4086 by @richardxia
- Support fields of type
Type[]
in schema, #4051 by @aminalaee - Add
default
value in JSON Schema whenconst=True
, #4031 by @aminalaee - Adds reserved word check to signature generation logic, #4011 by @strue36
- Fix Json strategy failure for the complex nested field, #4005 by @sergiosim
- Add JSON-compatible float constraint
allow_inf_nan
, #3994 by @tiangolo - Remove undefined behaviour when
env_prefix
had characters in common withenv_nested_delimiter
, #3975 by @arsenron - Support generics model with
create_model
, #3945 by @hot123s - allow submodels to overwrite extra field info, #3934 by @PrettyWood
- Document and test structural pattern matching (PEP 636) on
BaseModel
, #3920 by @irgolic - Fix incorrect deserialization of python timedelta object to ISO 8601 for negative time deltas. Minus was serialized in incorrect place ("P-1DT23H59M59.888735S" instead of correct "-P1DT23H59M59.888735S"), #3899 by @07pepa
- Fix validation of discriminated union fields with an alias when passing a model instance, #3846 by @chornsby
- Add a CockroachDsn type to validate CockroachDB connection strings. The type
supports the following schemes:
cockroachdb
,cockroachdb+psycopg2
andcockroachdb+asyncpg
, #3839 by @blubber - Fix MyPy plugin to not override pre-existing
__init__
method in models, #3824 by @patrick91 - Fix mypy version checking, #3783 by @KotlinIsland
- support overwriting dunder attributes of
BaseModel
instances, #3777 by @PrettyWood - Added
ConstrainedDate
andcondate
, #3740 by @hottwaj - Support
kw_only
in dataclasses, #3670 by @detachhead - Add comparison method for
Color
class, #3646 by @aminalaee - Drop support for python3.6, associated cleanup, #3605 by @samuelcolvin
- created new function
to_lower_camel()
for "non pascal case" camel case, #3463 by @schlerp - Add checks to
default
anddefault_factory
arguments in Mypy plugin, #3430 by @klaa97 - fix mangling of
inspect.signature
forBaseModel
, #3413 by @fix-inspect-signature - Adds the
SecretField
abstract class so that all the current and future secret fields likeSecretStr
andSecretBytes
will derive from it, #3409 by @expobrain - Support multi hosts validation in
PostgresDsn
, #3337 by @rglsk - Fix parsing of very small numeric timedelta values, #3315 by @samuelcolvin
- Update
SecretsSettingsSource
to respectconfig.case_sensitive
, #3273 by @JeanArhancet - Add MongoDB network data source name (DSN) schema, #3229 by @snosratiershad
- Add support for multiple dotenv files, #3222 by @rekyungmin
- Raise an explicit
ConfigError
when multiple fields are incorrectly set for a single validator, #3215 by @SunsetOrange - Allow ellipsis on
Field
s insideAnnotated
forTypedDicts
required, #3133 by @ezegomez - Catch overflow errors in
int_validator
, #3112 by @ojii - Adds a
__rich_repr__
method toRepresentation
class which enables pretty printing with Rich, #3099 by @willmcgugan - Add percent encoding in
AnyUrl
and descendent types, #3061 by @FaresAhmedb -
validate_arguments
decorator now supportsalias
, #3019 by @MAD-py - Avoid
__dict__
and__weakref__
attributes inAnyUrl
and IP address fields, #2890 by @nuno-andre - Add ability to use
Final
in a field type annotation, #2766 by @uriyyo - Update requirement to
typing_extensions>=4.1.0
to guaranteedataclass_transform
is available, #4424 by @commonism - Add Explosion and AWS to main sponsors, #4413 by @samuelcolvin
- Update documentation for
copy_on_model_validation
to reflect recent changes, #4369 by @samuelcolvin - Runtime warning if
__slots__
is passed tocreate_model
,__slots__
is then ignored, #4432 by @samuelcolvin - Add type hints to
BaseSettings.Config
to avoid mypy errors, also correct mypy version compatibility notice in docs, #4450 by @samuelcolvin
Full Changelog: https://github.com/pydantic/pydantic/compare/v1.9.0...v1.10.0