Skip to content

Commit 8c79238

Browse files
committed
Remove last of gil refs from model build
1 parent 0794434 commit 8c79238

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

src/input/input_python.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ impl<'a> Input<'a> for Py2<'a, PyAny> {
761761

762762
fn input_is_instance(&self, class: &PyType) -> Option<&PyAny> {
763763
if self.is_instance(Py2::borrowed_from_gil_ref(&&**class)).unwrap_or(false) {
764-
Some(self.clone().into_gil_ref())
764+
Some(self.as_gil_ref())
765765
} else {
766766
None
767767
}

src/validators/model_fields.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl BuildValidator for ModelFieldsValidator {
9494
fields.push(Field {
9595
name: field_name.to_string(),
9696
lookup_key,
97-
name_py: PyString::intern(py, field_name).into(),
97+
name_py: PyString::new2(py, field_name).into(),
9898
validator,
9999
frozen: field_info.get_as::<bool>(intern!(py, "frozen"))?.unwrap_or(false),
100100
});

src/validators/uuid.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ const UUID_IS_SAFE: &str = "is_safe";
2222
static UUID_TYPE: GILOnceCell<Py<PyType>> = GILOnceCell::new();
2323

2424
fn import_type(py: Python, module: &str, attr: &str) -> PyResult<Py<PyType>> {
25-
py.import(module)?.getattr(attr)?.extract()
25+
py.import2(module)?.getattr(attr)?.extract()
2626
}
2727

28-
fn get_uuid_type(py: Python) -> PyResult<&PyType> {
28+
fn get_uuid_type(py: Python) -> PyResult<&Py2<'_, PyType>> {
2929
Ok(UUID_TYPE
3030
.get_or_init(py, || import_type(py, "uuid", "UUID").unwrap())
31-
.as_ref(py))
31+
.attach(py))
3232
}
3333

3434
#[derive(Debug, Clone, Copy)]
@@ -92,7 +92,7 @@ impl Validator for UuidValidator {
9292
state: &mut ValidationState,
9393
) -> ValResult<PyObject> {
9494
let class = get_uuid_type(py)?;
95-
if let Some(py_input) = input.input_is_instance(class) {
95+
if let Some(py_input) = input.input_is_instance(class.as_gil_ref()) {
9696
if let Some(expected_version) = self.version {
9797
let py_input_version: Option<usize> = py_input.getattr(intern!(py, "version"))?.extract()?;
9898
if !match py_input_version {
@@ -125,7 +125,7 @@ impl Validator for UuidValidator {
125125
state.floor_exactness(Exactness::Lax);
126126
}
127127
let uuid = self.get_uuid(input)?;
128-
self.create_py_uuid(py, class, &uuid)
128+
self.create_py_uuid(class, &uuid)
129129
}
130130
}
131131

@@ -198,8 +198,9 @@ impl UuidValidator {
198198
///
199199
/// This implementation does not use the Python `__init__` function to speed up the process,
200200
/// as the `__init__` function in the Python `uuid` module performs extensive checks.
201-
fn create_py_uuid(&self, py: Python<'_>, py_type: &PyType, uuid: &Uuid) -> ValResult<Py<PyAny>> {
202-
let class = create_class(py_type)?;
201+
fn create_py_uuid(&self, py_type: &Py2<'_, PyType>, uuid: &Uuid) -> ValResult<Py<PyAny>> {
202+
let py = py_type.py();
203+
let class = create_class(py_type.as_gil_ref())?;
203204
let dc = class.as_ref(py);
204205
let int = uuid.as_u128();
205206
let safe = py

0 commit comments

Comments
 (0)