Remove uneeded syn::parse_str
from pyo3-derive-backend
This commit is contained in:
parent
3f4f068c7f
commit
4e3d828181
|
@ -113,7 +113,7 @@ fn extract_pyfn_attrs(
|
|||
// read Python fonction name
|
||||
match meta[1] {
|
||||
syn::NestedMeta::Literal(syn::Lit::Str(ref lits)) => {
|
||||
fnname = Some(syn::parse_str(&lits.value()).unwrap());
|
||||
fnname = Some(syn::Ident::new(&lits.value(), lits.span()));
|
||||
}
|
||||
_ => panic!("The second parameter of pyfn must be a Literal"),
|
||||
}
|
||||
|
|
|
@ -265,7 +265,8 @@ fn impl_class(
|
|||
};
|
||||
|
||||
let extra = if !descriptors.is_empty() {
|
||||
let ty = syn::parse_str(&cls.to_string()).expect("no name");
|
||||
let path = syn::Path::from(syn::PathSegment::from(cls.clone()));
|
||||
let ty = syn::Type::from(syn::TypePath { path, qself: None });
|
||||
let desc_impls = impl_descriptors(&ty, descriptors);
|
||||
quote! {
|
||||
#desc_impls
|
||||
|
@ -389,7 +390,7 @@ fn impl_descriptors(cls: &syn::Type, descriptors: Vec<(syn::Field, Vec<FnType>)>
|
|||
let name = field.ident.clone().unwrap();
|
||||
|
||||
// FIXME better doc?
|
||||
let doc: syn::Lit = syn::parse_str(&format!("\"{}\"", name)).unwrap();
|
||||
let doc = syn::Lit::from(syn::LitStr::new(&name.to_string(), name.span()));
|
||||
|
||||
let field_ty = &field.ty;
|
||||
match *desc {
|
||||
|
|
|
@ -5,6 +5,7 @@ use crate::func::impl_method_proto;
|
|||
use crate::method::FnSpec;
|
||||
use crate::pymethod;
|
||||
use proc_macro2::TokenStream;
|
||||
use proc_macro2::Span;
|
||||
use quote::quote;
|
||||
use quote::ToTokens;
|
||||
|
||||
|
@ -71,7 +72,7 @@ fn impl_proto_impl(
|
|||
for m in proto.py_methods {
|
||||
let ident = met.sig.ident.clone();
|
||||
if m.name == ident.to_string().as_str() {
|
||||
let name: syn::Ident = syn::parse_str(m.name).unwrap();
|
||||
let name = syn::Ident::new(m.name, Span::call_site());
|
||||
let proto: syn::Path = syn::parse_str(m.proto).unwrap();
|
||||
|
||||
let fn_spec = match FnSpec::parse(&ident, &met.sig, &mut met.attrs) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright (c) 2017-present PyO3 Project and Contributors
|
||||
|
||||
use proc_macro2::TokenStream;
|
||||
use proc_macro2::Span;
|
||||
use syn;
|
||||
|
||||
pub fn print_err(msg: String, t: TokenStream) {
|
||||
|
@ -32,13 +33,10 @@ pub fn get_doc(attrs: &[syn::Attribute], null_terminated: bool) -> syn::Lit {
|
|||
}
|
||||
}
|
||||
|
||||
let doc = doc.join("\n");
|
||||
let mut docstr = doc.join("\n");
|
||||
if null_terminated {
|
||||
docstr.push('\0');
|
||||
}
|
||||
|
||||
// FIXME: add span
|
||||
syn::parse_str(&if null_terminated {
|
||||
format!("\"{}\0\"", doc)
|
||||
} else {
|
||||
format!("\"{}\"", doc)
|
||||
})
|
||||
.unwrap()
|
||||
syn::Lit::Str(syn::LitStr::new(&docstr, Span::call_site()))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue