Merge pull request #456 from PyO3/unraw

Use syn::ext::IdentExt::unraw
This commit is contained in:
konstin 2019-04-28 13:55:53 +02:00 committed by GitHub
commit 6dbcd3cdc0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 15 deletions

View file

@ -19,7 +19,7 @@ travis-ci = { repository = "PyO3/pyo3", branch = "master" }
appveyor = { repository = "fafhrd91/pyo3" } appveyor = { repository = "fafhrd91/pyo3" }
[dependencies] [dependencies]
libc = "0.2.48" libc = "0.2.51"
spin = "0.5.0" spin = "0.5.0"
num-traits = "0.2.6" num-traits = "0.2.6"
pyo3cls = { path = "pyo3cls", version = "=0.7.0-alpha.1" } pyo3cls = { path = "pyo3cls", version = "=0.7.0-alpha.1" }
@ -33,7 +33,7 @@ assert_approx_eq = "1.1.0"
indoc = "0.3.1" indoc = "0.3.1"
[build-dependencies] [build-dependencies]
regex = "1.1.0" regex = "1.1.6"
version_check = "0.1.5" version_check = "0.1.5"
[features] [features]

View file

@ -11,6 +11,6 @@ license = "Apache-2.0"
edition = "2018" edition = "2018"
[dependencies] [dependencies]
quote = "0.6.9" quote = "0.6.12"
proc-macro2 = "0.4.20" proc-macro2 = "0.4.28"
syn = { version = "0.15.15", features = ["full", "extra-traits"] } syn = { version = "0.15.33", features = ["full", "extra-traits"] }

View file

@ -9,6 +9,7 @@ use crate::pymethod::get_arg_names;
use crate::utils; use crate::utils;
use proc_macro2::{Span, TokenStream}; use proc_macro2::{Span, TokenStream};
use quote::quote; use quote::quote;
use syn::ext::IdentExt;
use syn::Ident; use syn::Ident;
/// Generates the function that is called by the python interpreter to initialize the native /// Generates the function that is called by the python interpreter to initialize the native
@ -138,12 +139,8 @@ fn extract_pyfn_attrs(
/// Coordinates the naming of a the add-function-to-python-module function /// Coordinates the naming of a the add-function-to-python-module function
fn function_wrapper_ident(name: &Ident) -> Ident { fn function_wrapper_ident(name: &Ident) -> Ident {
// Make sure this ident matches the one of wrap_pyfunction // Make sure this ident matches the one of wrap_pyfunction
// The trim_start_matches("r#") is for https://github.com/dtolnay/syn/issues/478
Ident::new( Ident::new(
&format!( &format!("__pyo3_get_function_{}", name.unraw().to_string()),
"__pyo3_get_function_{}",
name.to_string().trim_start_matches("r#")
),
Span::call_site(), Span::call_site(),
) )
} }

View file

@ -10,6 +10,7 @@ use pyo3_derive_backend::{
process_functions_in_module, py_init, PyClassArgs, PyFunctionAttr, process_functions_in_module, py_init, PyClassArgs, PyFunctionAttr,
}; };
use quote::quote; use quote::quote;
use syn::ext::IdentExt;
use syn::parse_macro_input; use syn::parse_macro_input;
/// Internally, this proc macro create a new c function called `PyInit_{my_module}` /// Internally, this proc macro create a new c function called `PyInit_{my_module}`
@ -77,11 +78,7 @@ pub fn pyfunction(attr: TokenStream, input: TokenStream) -> TokenStream {
let ast = parse_macro_input!(input as syn::ItemFn); let ast = parse_macro_input!(input as syn::ItemFn);
let args = parse_macro_input!(attr as PyFunctionAttr); let args = parse_macro_input!(attr as PyFunctionAttr);
// Workaround for https://github.com/dtolnay/syn/issues/478 let python_name = syn::Ident::new(&ast.ident.unraw().to_string(), Span::call_site());
let python_name = syn::Ident::new(
&ast.ident.to_string().trim_start_matches("r#"),
Span::call_site(),
);
let expanded = add_fn_to_module(&ast, &python_name, args.arguments); let expanded = add_fn_to_module(&ast, &python_name, args.arguments);
quote!( quote!(