Skip to content

Commit d9227db

Browse files
committed
update to use new FromPyObject
1 parent 8d08c3d commit d9227db

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

src/errors/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,8 +781,8 @@ impl From<Int> for Number {
781781
}
782782

783783
impl FromPyObject<'_> for Number {
784-
fn extract(obj: &PyAny) -> PyResult<Self> {
785-
if let Ok(int) = extract_i64(Py2::borrowed_from_gil_ref(&obj)) {
784+
fn extract(obj: &Py2<'_, PyAny>) -> PyResult<Self> {
785+
if let Ok(int) = extract_i64(obj) {
786786
Ok(Number::Int(int))
787787
} else if let Ok(float) = obj.extract::<f64>() {
788788
Ok(Number::Float(float))

src/input/return_enums.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ impl<'a> Rem for &'a Int {
10311031
}
10321032

10331033
impl FromPyObject<'_> for Int {
1034-
fn extract(obj: &PyAny) -> PyResult<Self> {
1034+
fn extract(obj: &Py2<'_, PyAny>) -> PyResult<Self> {
10351035
if let Ok(i) = obj.extract::<i64>() {
10361036
Ok(Int::I64(i))
10371037
} else if let Ok(b) = obj.extract::<BigInt>() {

src/lookup_key.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,18 @@ impl fmt::Display for LookupKey {
5454
impl LookupKey {
5555
pub fn from_py(py: Python, value: &Py2<'_, PyAny>, alt_alias: Option<&str>) -> PyResult<Self> {
5656
if let Ok(alias_py) = value.downcast::<PyString>() {
57-
let alias: &str = alias_py.extract()?;
57+
let alias: String = alias_py.extract()?;
58+
let path1 = LookupPath::from_str(py, &alias, Some(alias_py.clone()));
5859
match alt_alias {
5960
Some(alt_alias) => Ok(Self::Choice {
6061
key1: alias.to_string(),
6162
py_key1: alias_py.clone().into(),
62-
path1: LookupPath::from_str(py, alias, Some(alias_py.clone())),
63+
path1,
6364
key2: alt_alias.to_string(),
6465
py_key2: PyString::new2(py, alt_alias).into(),
6566
path2: LookupPath::from_str(py, alt_alias, None),
6667
}),
67-
None => Ok(Self::simple(py, alias, Some(alias_py.clone()))),
68+
None => Ok(Self::simple(py, &alias, Some(alias_py.clone()))),
6869
}
6970
} else {
7071
let list = value.downcast::<PyList>()?;

src/serializers/config.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,7 @@ impl FromStr for InfNanMode {
217217
}
218218

219219
impl FromPyObject<'_> for InfNanMode {
220-
fn extract(ob: &PyAny) -> PyResult<Self> {
221-
let s = ob.extract::<&str>()?;
222-
Self::from_str(s)
220+
fn extract(ob: &Py2<'_, PyAny>) -> PyResult<Self> {
221+
Self::from_str(ob.downcast::<PyString>()?.to_str()?)
223222
}
224223
}

src/url.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,9 @@ impl UrlHostParts {
434434
}
435435

436436
impl FromPyObject<'_> for UrlHostParts {
437-
fn extract(ob: &PyAny) -> PyResult<Self> {
437+
fn extract(ob: &Py2<'_, PyAny>) -> PyResult<Self> {
438438
let py = ob.py();
439-
let dict = Py2::borrowed_from_gil_ref(&ob).downcast::<PyDict>()?;
439+
let dict = ob.downcast::<PyDict>()?;
440440
Ok(UrlHostParts {
441441
username: dict.get_as(intern!(py, "username"))?,
442442
password: dict.get_as(intern!(py, "password"))?,

0 commit comments

Comments
 (0)