Skip to content

Commit be87e05

Browse files
authored
Use UserWarning from pyo3 (#1559)
1 parent ab0e4bd commit be87e05

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/serializers/extra.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use std::fmt;
22
use std::sync::Mutex;
33

4-
use pyo3::exceptions::{PyTypeError, PyValueError};
5-
use pyo3::intern;
4+
use pyo3::exceptions::{PyTypeError, PyUserWarning, PyValueError};
65
use pyo3::prelude::*;
76
use pyo3::types::{PyBool, PyString};
7+
use pyo3::{intern, PyTypeInfo};
88

99
use serde::ser::Error;
1010

@@ -471,7 +471,7 @@ impl CollectWarnings {
471471

472472
let message = format!("Pydantic serializer warnings:\n {}", warnings.join("\n "));
473473
if self.mode == WarningsMode::Warn {
474-
let user_warning_type = py.import_bound("builtins")?.getattr("UserWarning")?;
474+
let user_warning_type = PyUserWarning::type_object(py);
475475
PyErr::warn_bound(py, &user_warning_type, &message, 0)
476476
} else {
477477
Err(PydanticSerializationError::new_err(message))

0 commit comments

Comments
 (0)