Skip to content

Commit eb7c63c

Browse files
committed
fixing frompyobject with DH
1 parent 6911297 commit eb7c63c

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

python/pydantic_core/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class ErrorTypeInfo(_TypedDict):
124124
"""Example of context values."""
125125

126126

127-
class MultiHostHost(_TypedDict):
127+
class MultiHostHost(_TypedDict, total=False):
128128
"""
129129
A host part of a multi-host URL.
130130
"""

src/url.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ use std::hash::{Hash, Hasher};
55

66
use idna::punycode::decode_to_string;
77
use pyo3::exceptions::PyValueError;
8-
use pyo3::prelude::*;
98
use pyo3::pyclass::CompareOp;
109
use pyo3::sync::GILOnceCell;
1110
use pyo3::types::{PyDict, PyType};
11+
use pyo3::{intern, prelude::*};
1212
use url::Url;
1313

14+
use crate::tools::SchemaDict;
1415
use crate::SchemaValidator;
1516

1617
static SCHEMA_DEFINITION_URL: GILOnceCell<SchemaValidator> = GILOnceCell::new();
@@ -422,8 +423,6 @@ impl PyMultiHostUrl {
422423
}
423424
}
424425

425-
#[derive(FromPyObject)]
426-
#[pyo3(from_item_all)]
427426
#[cfg_attr(debug_assertions, derive(Debug))]
428427
pub struct UrlHostParts {
429428
username: Option<String>,
@@ -438,6 +437,20 @@ impl UrlHostParts {
438437
}
439438
}
440439

440+
impl FromPyObject<'_> for UrlHostParts {
441+
fn extract_bound(ob: &Bound<'_, PyAny>) -> PyResult<Self> {
442+
let py = ob.py();
443+
let dict = ob.downcast::<PyDict>()?;
444+
445+
Ok(UrlHostParts {
446+
username: dict.get_as::<Option<_>>(intern!(py, "username"))?.flatten(),
447+
password: dict.get_as::<Option<_>>(intern!(py, "password"))?.flatten(),
448+
host: dict.get_as::<Option<_>>(intern!(py, "host"))?.flatten(),
449+
port: dict.get_as::<Option<_>>(intern!(py, "port"))?.flatten(),
450+
})
451+
}
452+
}
453+
441454
impl fmt::Display for UrlHostParts {
442455
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
443456
match (&self.username, &self.password) {

0 commit comments

Comments
 (0)