diff --git a/python/pydantic_core/_pydantic_core.pyi b/python/pydantic_core/_pydantic_core.pyi index a3e8117eb..17098cca5 100644 --- a/python/pydantic_core/_pydantic_core.pyi +++ b/python/pydantic_core/_pydantic_core.pyi @@ -392,7 +392,10 @@ def to_json( indent: int | None = None, include: _IncEx | None = None, exclude: _IncEx | None = None, - by_alias: bool | None = None, + # Note: In Pydantic 2.11, the default value of `by_alias` on `SchemaSerializer` was changed from `True` to `None`, + # to be consistent with the Pydantic "dump" methods. However, the default of `True` was kept here for + # backwards compatibility. In Pydantic V3, `by_alias` is expected to default to `True` everywhere: + by_alias: bool = True, exclude_none: bool = False, round_trip: bool = False, timedelta_mode: Literal['iso8601', 'float'] = 'iso8601', @@ -468,7 +471,10 @@ def to_jsonable_python( *, include: _IncEx | None = None, exclude: _IncEx | None = None, - by_alias: bool | None = None, + # Note: In Pydantic 2.11, the default value of `by_alias` on `SchemaSerializer` was changed from `True` to `None`, + # to be consistent with the Pydantic "dump" methods. However, the default of `True` was kept here for + # backwards compatibility. In Pydantic V3, `by_alias` is expected to default to `True` everywhere: + by_alias: bool = True, exclude_none: bool = False, round_trip: bool = False, timedelta_mode: Literal['iso8601', 'float'] = 'iso8601', diff --git a/src/serializers/mod.rs b/src/serializers/mod.rs index 6ed496aab..434b43c53 100644 --- a/src/serializers/mod.rs +++ b/src/serializers/mod.rs @@ -239,7 +239,7 @@ impl SchemaSerializer { #[allow(clippy::too_many_arguments)] #[pyfunction] -#[pyo3(signature = (value, *, indent = None, include = None, exclude = None, by_alias = None, +#[pyo3(signature = (value, *, indent = None, include = None, exclude = None, by_alias = true, exclude_none = false, round_trip = false, timedelta_mode = "iso8601", bytes_mode = "utf8", inf_nan_mode = "constants", serialize_unknown = false, fallback = None, serialize_as_any = false, context = None))] @@ -249,7 +249,7 @@ pub fn to_json( indent: Option, include: Option<&Bound<'_, PyAny>>, exclude: Option<&Bound<'_, PyAny>>, - by_alias: Option, + by_alias: bool, exclude_none: bool, round_trip: bool, timedelta_mode: &str, @@ -265,7 +265,7 @@ pub fn to_json( let extra = state.extra( py, &SerMode::Json, - by_alias, + Some(by_alias), exclude_none, round_trip, serialize_unknown, @@ -282,7 +282,7 @@ pub fn to_json( #[allow(clippy::too_many_arguments)] #[pyfunction] -#[pyo3(signature = (value, *, include = None, exclude = None, by_alias = None, exclude_none = false, round_trip = false, +#[pyo3(signature = (value, *, include = None, exclude = None, by_alias = true, exclude_none = false, round_trip = false, timedelta_mode = "iso8601", bytes_mode = "utf8", inf_nan_mode = "constants", serialize_unknown = false, fallback = None, serialize_as_any = false, context = None))] pub fn to_jsonable_python( @@ -290,7 +290,7 @@ pub fn to_jsonable_python( value: &Bound<'_, PyAny>, include: Option<&Bound<'_, PyAny>>, exclude: Option<&Bound<'_, PyAny>>, - by_alias: Option, + by_alias: bool, exclude_none: bool, round_trip: bool, timedelta_mode: &str, @@ -306,7 +306,7 @@ pub fn to_jsonable_python( let extra = state.extra( py, &SerMode::Json, - by_alias, + Some(by_alias), exclude_none, round_trip, serialize_unknown,