Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions python/pydantic_core/core_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -3904,6 +3904,7 @@ def url_schema(
default_host: str | None = None,
default_port: int | None = None,
default_path: str | None = None,
preserve_empty_path: bool | None = None,
strict: bool | None = None,
ref: str | None = None,
metadata: dict[str, Any] | None = None,
Expand All @@ -3928,6 +3929,7 @@ def url_schema(
default_host: The default host to use if the URL does not have a host
default_port: The default port to use if the URL does not have a port
default_path: The default path to use if the URL does not have a path
preserve_empty_path: Whether to preserve an empty path or convert it to '/', default False
strict: Whether to use strict URL parsing
ref: optional unique identifier of the schema, used to reference the schema in other places
metadata: Any other information you want to include with the schema, not used by pydantic-core
Expand All @@ -3941,6 +3943,7 @@ def url_schema(
default_host=default_host,
default_port=default_port,
default_path=default_path,
preserve_empty_path=preserve_empty_path,
strict=strict,
ref=ref,
metadata=metadata,
Expand Down Expand Up @@ -3970,6 +3973,7 @@ def multi_host_url_schema(
default_host: str | None = None,
default_port: int | None = None,
default_path: str | None = None,
preserve_empty_path: bool | None = None,
strict: bool | None = None,
ref: str | None = None,
metadata: dict[str, Any] | None = None,
Expand All @@ -3994,6 +3998,7 @@ def multi_host_url_schema(
default_host: The default host to use if the URL does not have a host
default_port: The default port to use if the URL does not have a port
default_path: The default path to use if the URL does not have a path
preserve_empty_path: Whether to preserve an empty path or convert it to '/', default False
strict: Whether to use strict URL parsing
ref: optional unique identifier of the schema, used to reference the schema in other places
metadata: Any other information you want to include with the schema, not used by pydantic-core
Expand All @@ -4007,6 +4012,7 @@ def multi_host_url_schema(
default_host=default_host,
default_port=default_port,
default_path=default_path,
preserve_empty_path=preserve_empty_path,
strict=strict,
ref=ref,
metadata=metadata,
Expand Down
12 changes: 6 additions & 6 deletions src/serializers/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,11 @@ pub(crate) fn infer_to_python_known(
}
ObType::Url => {
let py_url: PyUrl = value.extract()?;
py_url.__str__().into_py_any(py)?
py_url.__str__(py).into_py_any(py)?
}
ObType::MultiHostUrl => {
let py_url: PyMultiHostUrl = value.extract()?;
py_url.__str__().into_py_any(py)?
py_url.__str__(py).into_py_any(py)?
}
ObType::Uuid => {
let uuid = super::type_serializers::uuid::uuid_to_string(value)?;
Expand Down Expand Up @@ -476,11 +476,11 @@ pub(crate) fn infer_serialize_known<S: Serializer>(
}
ObType::Url => {
let py_url: PyUrl = value.extract().map_err(py_err_se_err)?;
serializer.serialize_str(py_url.__str__())
serializer.serialize_str(py_url.__str__(value.py()))
}
ObType::MultiHostUrl => {
let py_url: PyMultiHostUrl = value.extract().map_err(py_err_se_err)?;
serializer.serialize_str(&py_url.__str__())
serializer.serialize_str(&py_url.__str__(value.py()))
}
ObType::PydanticSerializable => {
let py = value.py();
Expand Down Expand Up @@ -644,11 +644,11 @@ pub(crate) fn infer_json_key_known<'a>(
}
ObType::Url => {
let py_url: PyUrl = key.extract()?;
Ok(Cow::Owned(py_url.__str__().to_string()))
Ok(Cow::Owned(py_url.__str__(key.py()).to_string()))
}
ObType::MultiHostUrl => {
let py_url: PyMultiHostUrl = key.extract()?;
Ok(Cow::Owned(py_url.__str__()))
Ok(Cow::Owned(py_url.__str__(key.py()).to_string()))
}
ObType::Tuple => {
let mut key_build = super::type_serializers::tuple::KeyBuilder::new();
Expand Down
6 changes: 3 additions & 3 deletions src/serializers/type_serializers/url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ macro_rules! build_serializer {
let py = value.py();
match value.extract::<$extract>() {
Ok(py_url) => match extra.mode {
SerMode::Json => py_url.__str__().into_py_any(py),
SerMode::Json => py_url.__str__(value.py()).into_py_any(py),
_ => Ok(value.clone().unbind()),
},
Err(_) => {
Expand All @@ -55,7 +55,7 @@ macro_rules! build_serializer {

fn json_key<'a>(&self, key: &'a Bound<'_, PyAny>, extra: &Extra) -> PyResult<Cow<'a, str>> {
match key.extract::<$extract>() {
Ok(py_url) => Ok(Cow::Owned(py_url.__str__().to_string())),
Ok(py_url) => Ok(Cow::Owned(py_url.__str__(key.py()).to_string())),
Err(_) => {
extra.warnings.on_fallback_py(self.get_name(), key, extra)?;
infer_json_key(key, extra)
Expand All @@ -72,7 +72,7 @@ macro_rules! build_serializer {
extra: &Extra,
) -> Result<S::Ok, S::Error> {
match value.extract::<$extract>() {
Ok(py_url) => serializer.serialize_str(&py_url.__str__()),
Ok(py_url) => serializer.serialize_str(&py_url.__str__(value.py())),
Err(_) => {
extra
.warnings
Expand Down
Loading
Loading