@@ -3,40 +3,40 @@ use core::fmt;
3
3
use num_bigint:: BigInt ;
4
4
5
5
use pyo3:: exceptions:: PyKeyError ;
6
+ use pyo3:: intern;
6
7
use pyo3:: prelude:: * ;
7
8
use pyo3:: types:: { PyDict , PyString } ;
8
- use pyo3:: { intern, FromPyObject } ;
9
9
10
10
use crate :: input:: Int ;
11
11
use jiter:: { cached_py_string, StringCacheMode } ;
12
12
13
13
pub trait SchemaDict < ' py > {
14
14
fn get_as < T > ( & self , key : & Bound < ' py , PyString > ) -> PyResult < Option < T > >
15
15
where
16
- T : FromPyObject < ' py > ;
16
+ T : FromPyObjectOwned < ' py > ;
17
17
18
18
fn get_as_req < T > ( & self , key : & Bound < ' py , PyString > ) -> PyResult < T >
19
19
where
20
- T : FromPyObject < ' py > ;
20
+ T : FromPyObjectOwned < ' py > ;
21
21
}
22
22
23
23
impl < ' py > SchemaDict < ' py > for Bound < ' py , PyDict > {
24
24
fn get_as < T > ( & self , key : & Bound < ' py , PyString > ) -> PyResult < Option < T > >
25
25
where
26
- T : FromPyObject < ' py > ,
26
+ T : FromPyObjectOwned < ' py > ,
27
27
{
28
28
match self . get_item ( key) ? {
29
- Some ( t) => t. extract ( ) . map ( Some ) ,
29
+ Some ( t) => t. extract ( ) . map_err ( Into :: into ) . map ( Some ) ,
30
30
None => Ok ( None ) ,
31
31
}
32
32
}
33
33
34
34
fn get_as_req < T > ( & self , key : & Bound < ' py , PyString > ) -> PyResult < T >
35
35
where
36
- T : FromPyObject < ' py > ,
36
+ T : FromPyObjectOwned < ' py > ,
37
37
{
38
38
match self . get_item ( key) ? {
39
- Some ( t) => t. extract ( ) ,
39
+ Some ( t) => t. extract ( ) . map_err ( Into :: into ) ,
40
40
None => py_err ! ( PyKeyError ; "{}" , key) ,
41
41
}
42
42
}
@@ -45,7 +45,7 @@ impl<'py> SchemaDict<'py> for Bound<'py, PyDict> {
45
45
impl < ' py > SchemaDict < ' py > for Option < & Bound < ' py , PyDict > > {
46
46
fn get_as < T > ( & self , key : & Bound < ' py , PyString > ) -> PyResult < Option < T > >
47
47
where
48
- T : FromPyObject < ' py > ,
48
+ T : FromPyObjectOwned < ' py > ,
49
49
{
50
50
match self {
51
51
Some ( d) => d. get_as ( key) ,
@@ -56,7 +56,7 @@ impl<'py> SchemaDict<'py> for Option<&Bound<'py, PyDict>> {
56
56
#[ cfg_attr( has_coverage_attribute, coverage( off) ) ]
57
57
fn get_as_req < T > ( & self , key : & Bound < ' py , PyString > ) -> PyResult < T >
58
58
where
59
- T : FromPyObject < ' py > ,
59
+ T : FromPyObjectOwned < ' py > ,
60
60
{
61
61
match self {
62
62
Some ( d) => d. get_as_req ( key) ,
0 commit comments