Skip to content

Commit 5caec09

Browse files
committed
Refactor PyConfig methods to improve readability by encapsulating configuration reads
1 parent 64faca2 commit 5caec09

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/config.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@ impl PyConfig {
5050

5151
/// Get a configuration option
5252
pub fn get<'py>(&self, key: &str, py: Python<'py>) -> PyResult<Bound<'py, PyAny>> {
53-
let options = self.config.read();
54-
for entry in options.entries() {
53+
let entries = {
54+
let options = self.config.read();
55+
options.entries()
56+
};
57+
58+
for entry in entries {
5559
if entry.key == key {
5660
return Ok(entry.value.into_pyobject(py)?);
5761
}
@@ -69,10 +73,14 @@ impl PyConfig {
6973

7074
/// Get all configuration options
7175
pub fn get_all(&self, py: Python) -> PyResult<PyObject> {
76+
let entries = {
77+
let options = self.config.read();
78+
options.entries()
79+
};
80+
7281
let dict = PyDict::new(py);
73-
let options = self.config.read();
74-
for entry in options.entries() {
75-
dict.set_item(entry.key, entry.value.clone().into_pyobject(py)?)?;
82+
for entry in entries {
83+
dict.set_item(entry.key, entry.value.into_pyobject(py)?)?;
7684
}
7785
Ok(dict.into())
7886
}

0 commit comments

Comments
 (0)