Skip to content

Commit

Permalink
Prepare release 2.4.0 (#7568)
Browse files Browse the repository at this point in the history
Co-authored-by: David Hewitt <1939362+davidhewitt@users.noreply.github.com>
  • Loading branch information
hramezani and davidhewitt committed Sep 25, 2023
1 parent 389c074 commit 6136b9a
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 20 deletions.
67 changes: 67 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,70 @@
## v2.4.0 (2023-09-22)

[GitHub release](https://github.com/pydantic/pydantic/releases/tag/v2.4.0)

### Packaging

* Update pydantic-core to 2.10.0 by @samuelcolvin in [#7542](https://github.com/pydantic/pydantic/pull/7542)

### New Features

* Add `Base64Url` types by @dmontagu in [#7286](https://github.com/pydantic/pydantic/pull/7286)
* Implement optional `number` to `str` coercion by @lig in [#7508](https://github.com/pydantic/pydantic/pull/7508)
* Allow access to `field_name` and `data` in all validators if there is data and a field name by @samuelcolvin in [#7542](https://github.com/pydantic/pydantic/pull/7542)
* Add `BaseModel.model_validate_strings` and `TypeAdapter.validate_strings` by @hramezani in [#7552](https://github.com/pydantic/pydantic/pull/7552)
* Add Pydantic `plugins` experimental implementation by @lig @samuelcolvin and in [#6820](https://github.com/pydantic/pydantic/pull/6820)

### Changes

* Do not override `model_post_init` in subclass with private attrs by @Viicos in [#7302](https://github.com/pydantic/pydantic/pull/7302)
* Make fields with defaults not required in the serialization schema by default by @dmontagu in [#7275](https://github.com/pydantic/pydantic/pull/7275)
* Mark `Extra` as deprecated by @disrupted in [#7299](https://github.com/pydantic/pydantic/pull/7299)
* Make `EncodedStr` a dataclass by @Kludex in [#7396](https://github.com/pydantic/pydantic/pull/7396)
* Move `annotated_handlers` to be public by @samuelcolvin in [#7569](https://github.com/pydantic/pydantic/pull/7569)

### Performance

* Simplify flattening and inlining of `CoreSchema` by @adriangb in [#7523](https://github.com/pydantic/pydantic/pull/7523)
* Remove unused copies in `CoreSchema` walking by @adriangb in [#7528](https://github.com/pydantic/pydantic/pull/7528)
* Add caches for collecting definitions and invalid schemas from a CoreSchema by @adriangb in [#7527](https://github.com/pydantic/pydantic/pull/7527)
* Eagerly resolve discriminated unions and cache cases where we can't by @adriangb in [#7529](https://github.com/pydantic/pydantic/pull/7529)
* Replace `dict.get` and `dict.setdefault` with more verbose versions in `CoreSchema` building hot paths by @adriangb in [#7536](https://github.com/pydantic/pydantic/pull/7536)
* Cache invalid `CoreSchema` discovery by @adriangb in [#7535](https://github.com/pydantic/pydantic/pull/7535)
* Allow disabling `CoreSchema` validation for faster startup times by @adriangb in [#7565](https://github.com/pydantic/pydantic/pull/7565)

### Fixes

* Fix config detection for `TypedDict` from grandparent classes by @dmontagu in [#7272](https://github.com/pydantic/pydantic/pull/7272)
* Fix hash function generation for frozen models with unusual MRO by @dmontagu in [#7274](https://github.com/pydantic/pydantic/pull/7274)
* Make `strict` config overridable in field for Path by @hramezani in [#7281](https://github.com/pydantic/pydantic/pull/7281)
* Use `ser_json_<timedelta|bytes>` on default in `GenerateJsonSchema` by @Kludex in [#7269](https://github.com/pydantic/pydantic/pull/7269)
* Adding a check that alias is validated as an identifier for Python by @andree0 in [#7319](https://github.com/pydantic/pydantic/pull/7319)
* Raise an error when computed field overrides field by @sydney-runkle in [#7346](https://github.com/pydantic/pydantic/pull/7346)
* Fix applying `SkipValidation` to referenced schemas by @adriangb in [#7381](https://github.com/pydantic/pydantic/pull/7381)
* Enforce behavior of private attributes having double leading underscore by @lig in [#7265](https://github.com/pydantic/pydantic/pull/7265)
* Standardize `__get_pydantic_core_schema__` signature by @hramezani in [#7415](https://github.com/pydantic/pydantic/pull/7415)
* Fix generic dataclass fields mutation bug (when using `TypeAdapter`) by @sydney-runkle in [#7435](https://github.com/pydantic/pydantic/pull/7435)
* Fix `TypeError` on `model_validator` in `wrap` mode by @pmmmwh in [#7496](https://github.com/pydantic/pydantic/pull/7496)
* Improve enum error message by @hramezani in [#7506](https://github.com/pydantic/pydantic/pull/7506)
* Make `repr` work for instances that failed initialization when handling `ValidationError`s by @dmontagu in [#7439](https://github.com/pydantic/pydantic/pull/7439)
* Fixed a regular expression denial of service issue by limiting whitespaces by @prodigysml in [#7360](https://github.com/pydantic/pydantic/pull/7360)
* Fix handling of `UUID` values having `UUID.version=None` by @lig in [#7566](https://github.com/pydantic/pydantic/pull/7566)
* Fix `__iter__` returning private `cached_property` info by @sydney-runkle in [#7570](https://github.com/pydantic/pydantic/pull/7570)
* Improvements to version info message by @samuelcolvin in [#7594](https://github.com/pydantic/pydantic/pull/7594)

### New Contributors
* @15498th made their first contribution in [#7238](https://github.com/pydantic/pydantic/pull/7238)
* @GabrielCappelli made their first contribution in [#7213](https://github.com/pydantic/pydantic/pull/7213)
* @tobni made their first contribution in [#7184](https://github.com/pydantic/pydantic/pull/7184)
* @redruin1 made their first contribution in [#7282](https://github.com/pydantic/pydantic/pull/7282)
* @FacerAin made their first contribution in [#7288](https://github.com/pydantic/pydantic/pull/7288)
* @acdha made their first contribution in [#7297](https://github.com/pydantic/pydantic/pull/7297)
* @andree0 made their first contribution in [#7319](https://github.com/pydantic/pydantic/pull/7319)
* @gordonhart made their first contribution in [#7375](https://github.com/pydantic/pydantic/pull/7375)
* @pmmmwh made their first contribution in [#7496](https://github.com/pydantic/pydantic/pull/7496)
* @disrupted made their first contribution in [#7299](https://github.com/pydantic/pydantic/pull/7299)
* @prodigysml made their first contribution in [#7360](https://github.com/pydantic/pydantic/pull/7360)

## v2.3.0 (2023-08-23)

[GitHub release](https://github.com/pydantic/pydantic/releases/tag/v2.3.0)
Expand Down
2 changes: 1 addition & 1 deletion pydantic/dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def dataclass(
kw_only: bool = False,
slots: bool = False,
) -> Callable[[type[_T]], type[PydanticDataclass]] | type[PydanticDataclass]:
"""Usage docs: https://docs.pydantic.dev/2.3/concepts/dataclasses/
"""Usage docs: https://docs.pydantic.dev/2.4/concepts/dataclasses/
A decorator used to create a Pydantic-enhanced dataclass, similar to the standard Python `dataclass`,
but with added validation.
Expand Down
6 changes: 3 additions & 3 deletions pydantic/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ def __repr_args__(self) -> ReprArgs:

@dataclasses.dataclass(**_internal_dataclass.slots_true)
class AliasPath:
"""Usage docs: https://docs.pydantic.dev/2.3/concepts/fields#aliaspath-and-aliaschoices
"""Usage docs: https://docs.pydantic.dev/2.4/concepts/fields#aliaspath-and-aliaschoices
A data class used by `validation_alias` as a convenience to create aliases.
Expand All @@ -604,7 +604,7 @@ def convert_to_aliases(self) -> list[str | int]:

@dataclasses.dataclass(**_internal_dataclass.slots_true)
class AliasChoices:
"""Usage docs: https://docs.pydantic.dev/2.3/concepts/fields#aliaspath-and-aliaschoices
"""Usage docs: https://docs.pydantic.dev/2.4/concepts/fields#aliaspath-and-aliaschoices
A data class used by `validation_alias` as a convenience to create aliases.
Expand Down Expand Up @@ -703,7 +703,7 @@ def Field( # noqa: C901
union_mode: Literal['smart', 'left_to_right'] = _Unset,
**extra: Unpack[_EmptyKwargs],
) -> Any:
"""Usage docs: https://docs.pydantic.dev/2.3/concepts/fields
"""Usage docs: https://docs.pydantic.dev/2.4/concepts/fields
Create a field for objects that can be configured.
Expand Down
8 changes: 4 additions & 4 deletions pydantic/functional_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def __get_pydantic_core_schema__(self, source_type: Any, handler: _GetCoreSchema

@dataclasses.dataclass(frozen=True, **_internal_dataclass.slots_true)
class BeforeValidator:
"""Usage docs: https://docs.pydantic.dev/2.3/concepts/validators/#annotated-validators
"""Usage docs: https://docs.pydantic.dev/2.4/concepts/validators/#annotated-validators
A metadata class that indicates that a validation should be applied **before** the inner validation logic.
Expand Down Expand Up @@ -128,7 +128,7 @@ def __get_pydantic_core_schema__(self, source_type: Any, handler: _GetCoreSchema

@dataclasses.dataclass(frozen=True, **_internal_dataclass.slots_true)
class PlainValidator:
"""Usage docs: https://docs.pydantic.dev/2.3/concepts/validators/#annotated-validators
"""Usage docs: https://docs.pydantic.dev/2.4/concepts/validators/#annotated-validators
A metadata class that indicates that a validation should be applied **instead** of the inner validation logic.
Expand Down Expand Up @@ -165,7 +165,7 @@ def __get_pydantic_core_schema__(self, source_type: Any, handler: _GetCoreSchema

@dataclasses.dataclass(frozen=True, **_internal_dataclass.slots_true)
class WrapValidator:
"""Usage docs: https://docs.pydantic.dev/2.3/concepts/validators/#annotated-validators
"""Usage docs: https://docs.pydantic.dev/2.4/concepts/validators/#annotated-validators
A metadata class that indicates that a validation should be applied **around** the inner validation logic.
Expand Down Expand Up @@ -285,7 +285,7 @@ def field_validator(
mode: FieldValidatorModes = 'after',
check_fields: bool | None = None,
) -> Callable[[Any], Any]:
"""Usage docs: https://docs.pydantic.dev/2.3/concepts/validators/#field-validators
"""Usage docs: https://docs.pydantic.dev/2.4/concepts/validators/#field-validators
Decorate methods on the class indicating that they should be used to validate fields.
Expand Down
8 changes: 4 additions & 4 deletions pydantic/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@


class BaseModel(metaclass=_model_construction.ModelMetaclass):
"""Usage docs: https://docs.pydantic.dev/2.3/concepts/models/
"""Usage docs: https://docs.pydantic.dev/2.4/concepts/models/
A base class for creating Pydantic models.
Expand Down Expand Up @@ -245,7 +245,7 @@ def model_construct(cls: type[Model], _fields_set: set[str] | None = None, **val
return m

def model_copy(self: Model, *, update: dict[str, Any] | None = None, deep: bool = False) -> Model:
"""Usage docs: https://docs.pydantic.dev/2.3/concepts/serialization/#model_copy
"""Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#model_copy
Returns a copy of the model.
Expand Down Expand Up @@ -285,7 +285,7 @@ def model_dump(
round_trip: bool = False,
warnings: bool = True,
) -> dict[str, Any]:
"""Usage docs: https://docs.pydantic.dev/2.3/concepts/serialization/#modelmodel_dump
"""Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
Expand Down Expand Up @@ -331,7 +331,7 @@ def model_dump_json(
round_trip: bool = False,
warnings: bool = True,
) -> str:
"""Usage docs: https://docs.pydantic.dev/2.3/concepts/serialization/#modelmodel_dump_json
"""Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump_json
Generates a JSON representation of the model using Pydantic's `to_json` method.
Expand Down
2 changes: 1 addition & 1 deletion pydantic/plugin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Usage docs: https://docs.pydantic.dev/2.3/concepts/plugins#build-a-plugin
"""Usage docs: https://docs.pydantic.dev/2.4/concepts/plugins#build-a-plugin
Plugin interface for Pydantic plugins, and related types.
"""
Expand Down
2 changes: 1 addition & 1 deletion pydantic/root_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@


class RootModel(BaseModel, typing.Generic[RootModelRootType]):
"""Usage docs: https://docs.pydantic.dev/2.3/concepts/models/#rootmodel-and-custom-root-types
"""Usage docs: https://docs.pydantic.dev/2.4/concepts/models/#rootmodel-and-custom-root-types
A Pydantic `BaseModel` for the root object of the model.
Expand Down
2 changes: 1 addition & 1 deletion pydantic/validate_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def validate_call(
config: ConfigDict | None = None,
validate_return: bool = False,
) -> AnyCallableT | Callable[[AnyCallableT], AnyCallableT]:
"""Usage docs: https://docs.pydantic.dev/2.3/concepts/validation_decorator/
"""Usage docs: https://docs.pydantic.dev/2.4/concepts/validation_decorator/
Returns a decorated wrapper around the function that validates the arguments and, optionally, the return value.
Expand Down
2 changes: 1 addition & 1 deletion pydantic/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

__all__ = 'VERSION', 'version_info'

VERSION = '2.3.0'
VERSION = '2.4.0'
"""The version of Pydantic."""


Expand Down
6 changes: 2 additions & 4 deletions tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,12 @@ def enter(

def on_error(self, error: ValidationError) -> None:
assert error.title == 'Model'
assert error.errors() == [
assert error.errors(include_url=False) == [
{
'input': 'potato',
'loc': ('a',),
'msg': 'Input should be a valid integer, unable to parse string as an ' 'integer',
'type': 'int_parsing',
'url': 'https://errors.pydantic.dev/2.3/v/int_parsing',
},
]

Expand Down Expand Up @@ -155,13 +154,12 @@ def enter(

def on_error(self, error: ValidationError) -> None:
assert error.title == 'Model'
assert error.errors() == [
assert error.errors(include_url=False) == [
{
'input': 'potato',
'loc': ('a',),
'msg': 'Input should be a valid integer, unable to parse string as an ' 'integer',
'type': 'int_parsing',
'url': 'https://errors.pydantic.dev/2.3/v/int_parsing',
},
]

Expand Down

0 comments on commit 6136b9a

Please sign in to comment.