MCPcopy Create free account
hub / github.com/PyO3/pyo3 / expr_to_python

Function expr_to_python

pyo3-macros-backend/src/utils.rs:301–327  ·  view source on GitHub ↗
(expr: &syn::Expr)

Source from the content-addressed store, hash-verified

299}
300
301pub fn expr_to_python(expr: &syn::Expr) -> String {
302 match expr {
303 // literal values
304 syn::Expr::Lit(syn::ExprLit { lit, .. }) => match lit {
305 syn::Lit::Str(s) => s.token().to_string(),
306 syn::Lit::Char(c) => c.token().to_string(),
307 syn::Lit::Int(i) => i.base10_digits().to_string(),
308 syn::Lit::Float(f) => f.base10_digits().to_string(),
309 syn::Lit::Bool(b) => {
310 if b.value() {
311 "True".to_string()
312 } else {
313 "False".to_string()
314 }
315 }
316 _ => "...".to_string(),
317 },
318 // None
319 syn::Expr::Path(syn::ExprPath { qself, path, .. })
320 if qself.is_none() && path.is_ident("None") =>
321 {
322 "None".to_string()
323 }
324 // others, unsupported yet so defaults to `...`
325 _ => "...".to_string(),
326 }
327}
328
329/// Helper struct for hard-coded identifiers used in the macro code.
330#[derive(Clone, Copy)]

Callers 1

text_signatureMethod · 0.85

Calls 3

to_stringMethod · 0.80
valueMethod · 0.45
is_noneMethod · 0.45

Tested by

no test coverage detected