11#![ allow( unexpected_cfgs, unsafe_op_in_unsafe_fn) ]
2+ // The #[pyfunction] macro generates FFI wrapper code that calls From<PyErr>::from(err)
3+ // on the error path of every wrapped function. Since PyErr: From<PyErr> is the identity
4+ // impl, clippy flags it as useless_conversion. We cannot change macro-generated code,
5+ // so suppress the lint at crate level.
6+ #![ allow( clippy:: useless_conversion) ]
27
38use pyo3:: {
49 create_exception,
@@ -67,7 +72,7 @@ fn serialize<'py, T>(py: Python<'py>, value: &T) -> PyResult<PyObject>
6772where
6873 T : Serialize ,
6974{
70- Ok ( pythonize ( py, value) ?. unbind ( ) . into ( ) )
75+ Ok ( pythonize ( py, value) ?. unbind ( ) )
7176}
7277
7378fn login_payload ( status : AccountStatus ) -> LoginPayload {
@@ -120,18 +125,18 @@ fn signup_with_client(
120125 email : & str ,
121126 password : & str ,
122127) -> PyResult < PyObject > {
123- let env = parse_env ( env) ? ;
124- let client = client_credentials ( app_id, app_secret) ;
125- let result = runtime ( )
126- . block_on ( rust_signup_with_client (
127- env,
128- client,
129- email. to_string ( ) ,
130- password. to_string ( ) ,
131- ) )
132- . map_err ( native_error) ? ;
133-
134- serialize ( py , & result )
128+ parse_env ( env) . and_then ( |env| {
129+ let client = client_credentials ( app_id, app_secret) ;
130+ runtime ( )
131+ . block_on ( rust_signup_with_client (
132+ env,
133+ client,
134+ email. to_string ( ) ,
135+ password. to_string ( ) ,
136+ ) )
137+ . map_err ( native_error)
138+ . and_then ( |result| serialize ( py , & result ) )
139+ } )
135140}
136141
137142#[ pyfunction]
@@ -143,19 +148,19 @@ fn login_with_client(
143148 email : & str ,
144149 password : & str ,
145150) -> PyResult < PyObject > {
146- let env = parse_env ( env) ? ;
147- let client = client_credentials ( app_id, app_secret) ;
148- let result = runtime ( )
149- . block_on ( rust_login_with_client (
150- env,
151- client,
152- email. to_string ( ) ,
153- password. to_string ( ) ,
154- ) )
155- . map ( login_payload)
156- . map_err ( native_error) ? ;
157-
158- serialize ( py , & result )
151+ parse_env ( env) . and_then ( |env| {
152+ let client = client_credentials ( app_id, app_secret) ;
153+ runtime ( )
154+ . block_on ( rust_login_with_client (
155+ env,
156+ client,
157+ email. to_string ( ) ,
158+ password. to_string ( ) ,
159+ ) )
160+ . map ( login_payload)
161+ . map_err ( native_error)
162+ . and_then ( |result| serialize ( py , & result ) )
163+ } )
159164}
160165
161166#[ pyfunction]
@@ -165,16 +170,16 @@ fn logout_with_client(
165170 app_secret : & str ,
166171 access_token : & str ,
167172) -> PyResult < ( ) > {
168- let env = parse_env ( env) ? ;
169- let client = client_credentials ( app_id, app_secret) ;
170-
171- runtime ( )
172- . block_on ( rust_logout_with_client (
173- env ,
174- client ,
175- access_token . to_string ( ) ,
176- ) )
177- . map_err ( native_error )
173+ parse_env ( env) . and_then ( |env| {
174+ let client = client_credentials ( app_id, app_secret) ;
175+ runtime ( )
176+ . block_on ( rust_logout_with_client (
177+ env ,
178+ client ,
179+ access_token . to_string ( ) ,
180+ ) )
181+ . map_err ( native_error )
182+ } )
178183}
179184
180185#[ pyfunction]
@@ -185,13 +190,13 @@ fn me_with_client(
185190 app_secret : & str ,
186191 access_token : & str ,
187192) -> PyResult < PyObject > {
188- let env = parse_env ( env) ? ;
189- let client = client_credentials ( app_id, app_secret) ;
190- let result = runtime ( )
191- . block_on ( rust_me_with_client ( env, client, access_token) )
192- . map_err ( native_error) ? ;
193-
194- serialize ( py , & result )
193+ parse_env ( env) . and_then ( |env| {
194+ let client = client_credentials ( app_id, app_secret) ;
195+ runtime ( )
196+ . block_on ( rust_me_with_client ( env, client, access_token) )
197+ . map_err ( native_error)
198+ . and_then ( |result| serialize ( py , & result ) )
199+ } )
195200}
196201
197202#[ pyfunction]
@@ -201,12 +206,12 @@ fn remove_with_client(
201206 app_secret : & str ,
202207 access_token : & str ,
203208) -> PyResult < ( ) > {
204- let env = parse_env ( env) ? ;
205- let client = client_credentials ( app_id, app_secret) ;
206-
207- runtime ( )
208- . block_on ( rust_remove_with_client ( env , client , access_token ) )
209- . map_err ( native_error )
209+ parse_env ( env) . and_then ( |env| {
210+ let client = client_credentials ( app_id, app_secret) ;
211+ runtime ( )
212+ . block_on ( rust_remove_with_client ( env , client , access_token ) )
213+ . map_err ( native_error )
214+ } )
210215}
211216
212217#[ pymodule( name = "_native" ) ]
0 commit comments