pyo3_path: rename internal types/variables to Crate/krate

This commit is contained in:
Georg Brandl 2021-12-09 09:06:39 +01:00
parent 2d49dc33b7
commit d0381c25e5
9 changed files with 101 additions and 102 deletions

View File

@ -45,14 +45,14 @@ impl Parse for NameAttribute {
/// For specifying the path to the pyo3 crate.
#[derive(Clone, Debug, PartialEq)]
pub struct PyO3PathAttribute(pub Path);
pub struct CrateAttribute(pub Path);
impl Parse for PyO3PathAttribute {
impl Parse for CrateAttribute {
fn parse(input: ParseStream) -> Result<Self> {
let _: Token![crate] = input.parse()?;
let _: Token![=] = input.parse()?;
let string_literal: LitStr = input.parse()?;
string_literal.parse().map(PyO3PathAttribute)
string_literal.parse().map(CrateAttribute)
}
}

View File

@ -1,6 +1,6 @@
use crate::{
attributes::{self, get_pyo3_options, FromPyWithAttribute, PyO3PathAttribute},
utils::get_pyo3_path,
attributes::{self, get_pyo3_options, CrateAttribute, FromPyWithAttribute},
utils::get_pyo3_crate,
};
use proc_macro2::TokenStream;
use quote::quote;
@ -310,7 +310,7 @@ struct ContainerOptions {
/// Change the name of an enum variant in the generated error message.
annotation: Option<syn::LitStr>,
/// Change the path for the pyo3 crate
pyo3_path: Option<PyO3PathAttribute>,
krate: Option<CrateAttribute>,
}
/// Attributes for deriving FromPyObject scoped on containers.
@ -321,7 +321,7 @@ enum ContainerPyO3Attribute {
/// Change the name of an enum variant in the generated error message.
ErrorAnnotation(LitStr),
/// Change the path for the pyo3 crate
PyO3Path(PyO3PathAttribute),
Crate(CrateAttribute),
}
impl Parse for ContainerPyO3Attribute {
@ -335,7 +335,7 @@ impl Parse for ContainerPyO3Attribute {
let _: Token![=] = input.parse()?;
input.parse().map(ContainerPyO3Attribute::ErrorAnnotation)
} else if lookahead.peek(Token![crate]) {
input.parse().map(ContainerPyO3Attribute::PyO3Path)
input.parse().map(ContainerPyO3Attribute::Crate)
} else {
Err(lookahead.error())
}
@ -364,12 +364,12 @@ impl ContainerOptions {
);
options.annotation = Some(lit_str);
}
ContainerPyO3Attribute::PyO3Path(path) => {
ContainerPyO3Attribute::Crate(path) => {
ensure_spanned!(
options.pyo3_path.is_none(),
path.0.span() => "`pyo3_path` may only be provided once"
options.krate.is_none(),
path.0.span() => "`crate` may only be provided once"
);
options.pyo3_path = Some(path);
options.krate = Some(path);
}
}
}
@ -515,7 +515,7 @@ pub fn build_derive_from_pyobject(tokens: &DeriveInput) -> Result<TokenStream> {
.push(parse_quote!(#gen_ident: FromPyObject<#lt_param>))
}
let options = ContainerOptions::from_attrs(&tokens.attrs)?;
let pyo3_path = get_pyo3_path(&options.pyo3_path);
let krate = get_pyo3_crate(&options.krate);
let derives = match &tokens.data {
syn::Data::Enum(en) => {
if options.transparent || options.annotation.is_some() {
@ -541,7 +541,7 @@ pub fn build_derive_from_pyobject(tokens: &DeriveInput) -> Result<TokenStream> {
let ident = &tokens.ident;
Ok(quote!(
const _: () = {
use #pyo3_path as _pyo3;
use #krate as _pyo3;
#[automatically_derived]
impl#trait_generics _pyo3::FromPyObject<#lt_param> for #ident#generics #where_clause {

View File

@ -5,7 +5,7 @@ use crate::deprecations::Deprecation;
use crate::params::{accept_args_kwargs, impl_arg_params};
use crate::pyfunction::PyFunctionOptions;
use crate::pyfunction::{PyFunctionArgPyO3Attributes, PyFunctionSignature};
use crate::utils::{self, get_pyo3_path, PythonDoc};
use crate::utils::{self, get_pyo3_crate, PythonDoc};
use crate::{deprecations::Deprecations, pyfunction::Argument};
use proc_macro2::{Span, TokenStream};
use quote::ToTokens;
@ -228,7 +228,7 @@ pub struct FnSpec<'a> {
pub deprecations: Deprecations,
pub convention: CallingConvention,
pub text_signature: Option<TextSignatureAttribute>,
pub pyo3_path: syn::Path,
pub krate: syn::Path,
}
pub fn get_return_info(output: &syn::ReturnType) -> syn::Type {
@ -262,7 +262,7 @@ impl<'a> FnSpec<'a> {
) -> Result<FnSpec<'a>> {
let PyFunctionOptions {
text_signature,
pyo3_path,
krate,
name,
mut deprecations,
..
@ -281,7 +281,7 @@ impl<'a> FnSpec<'a> {
let name = &sig.ident;
let ty = get_return_info(&sig.output);
let python_name = python_name.as_ref().unwrap_or(name).unraw();
let pyo3_path = get_pyo3_path(&pyo3_path);
let krate = get_pyo3_crate(&krate);
let doc = utils::get_doc(
meth_attrs,
@ -315,7 +315,7 @@ impl<'a> FnSpec<'a> {
doc,
deprecations,
text_signature,
pyo3_path,
krate,
})
}
@ -477,16 +477,16 @@ impl<'a> FnSpec<'a> {
};
let rust_call =
quote! { _pyo3::callback::convert(#py, #rust_name(#self_arg #(#arg_names),*)) };
let pyo3_path = &self.pyo3_path;
let krate = &self.krate;
Ok(match self.convention {
CallingConvention::Noargs => {
quote! {
unsafe extern "C" fn #ident (
_slf: *mut #pyo3_path::ffi::PyObject,
_args: *mut #pyo3_path::ffi::PyObject,
) -> *mut #pyo3_path::ffi::PyObject
_slf: *mut #krate::ffi::PyObject,
_args: *mut #krate::ffi::PyObject,
) -> *mut #krate::ffi::PyObject
{
use #pyo3_path as _pyo3;
use #krate as _pyo3;
#deprecations
_pyo3::callback::handle_panic(|#py| {
#self_conversion
@ -499,12 +499,12 @@ impl<'a> FnSpec<'a> {
let arg_convert_and_rust_call = impl_arg_params(self, cls, rust_call, &py, true)?;
quote! {
unsafe extern "C" fn #ident (
_slf: *mut #pyo3_path::ffi::PyObject,
_args: *const *mut #pyo3_path::ffi::PyObject,
_nargs: #pyo3_path::ffi::Py_ssize_t,
_kwnames: *mut #pyo3_path::ffi::PyObject) -> *mut #pyo3_path::ffi::PyObject
_slf: *mut #krate::ffi::PyObject,
_args: *const *mut #krate::ffi::PyObject,
_nargs: #krate::ffi::Py_ssize_t,
_kwnames: *mut #krate::ffi::PyObject) -> *mut #krate::ffi::PyObject
{
use #pyo3_path as _pyo3;
use #krate as _pyo3;
#deprecations
_pyo3::callback::handle_panic(|#py| {
#self_conversion
@ -527,11 +527,11 @@ impl<'a> FnSpec<'a> {
let arg_convert_and_rust_call = impl_arg_params(self, cls, rust_call, &py, false)?;
quote! {
unsafe extern "C" fn #ident (
_slf: *mut #pyo3_path::ffi::PyObject,
_args: *mut #pyo3_path::ffi::PyObject,
_kwargs: *mut #pyo3_path::ffi::PyObject) -> *mut #pyo3_path::ffi::PyObject
_slf: *mut #krate::ffi::PyObject,
_args: *mut #krate::ffi::PyObject,
_kwargs: *mut #krate::ffi::PyObject) -> *mut #krate::ffi::PyObject
{
use #pyo3_path as _pyo3;
use #krate as _pyo3;
#deprecations
_pyo3::callback::handle_panic(|#py| {
#self_conversion
@ -548,11 +548,11 @@ impl<'a> FnSpec<'a> {
let arg_convert_and_rust_call = impl_arg_params(self, cls, rust_call, &py, false)?;
quote! {
unsafe extern "C" fn #ident (
subtype: *mut #pyo3_path::ffi::PyTypeObject,
_args: *mut #pyo3_path::ffi::PyObject,
_kwargs: *mut #pyo3_path::ffi::PyObject) -> *mut #pyo3_path::ffi::PyObject
subtype: *mut #krate::ffi::PyTypeObject,
_args: *mut #krate::ffi::PyObject,
_kwargs: *mut #krate::ffi::PyObject) -> *mut #krate::ffi::PyObject
{
use #pyo3_path as _pyo3;
use #krate as _pyo3;
#deprecations
use _pyo3::callback::IntoPyCallbackOutput;
_pyo3::callback::handle_panic(|#py| {

View File

@ -3,11 +3,10 @@
use crate::{
attributes::{
self, is_attribute_ident, take_attributes, take_pyo3_options, NameAttribute,
PyO3PathAttribute,
self, is_attribute_ident, take_attributes, take_pyo3_options, CrateAttribute, NameAttribute,
},
pyfunction::{impl_wrap_pyfunction, PyFunctionOptions},
utils::{get_pyo3_path, PythonDoc},
utils::{get_pyo3_crate, PythonDoc},
};
use proc_macro2::{Span, TokenStream};
use quote::quote;
@ -21,7 +20,7 @@ use syn::{
#[derive(Default)]
pub struct PyModuleOptions {
pyo3_path: Option<PyO3PathAttribute>,
krate: Option<CrateAttribute>,
name: Option<syn::Ident>,
}
@ -32,7 +31,7 @@ impl PyModuleOptions {
for option in take_pyo3_options(attrs)? {
match option {
PyModulePyO3Option::Name(name) => options.set_name(name.0)?,
PyModulePyO3Option::PyO3Path(path) => options.set_pyo3_path(path)?,
PyModulePyO3Option::Crate(path) => options.set_crate(path)?,
}
}
@ -49,13 +48,13 @@ impl PyModuleOptions {
Ok(())
}
fn set_pyo3_path(&mut self, path: PyO3PathAttribute) -> Result<()> {
fn set_crate(&mut self, path: CrateAttribute) -> Result<()> {
ensure_spanned!(
self.pyo3_path.is_none(),
path.0.span() => "`pyo3_path` may only be specified once"
self.krate.is_none(),
path.0.span() => "`crate` may only be specified once"
);
self.pyo3_path = Some(path);
self.krate = Some(path);
Ok(())
}
}
@ -64,7 +63,7 @@ impl PyModuleOptions {
/// module
pub fn py_init(fnname: &Ident, options: PyModuleOptions, doc: PythonDoc) -> TokenStream {
let name = options.name.unwrap_or_else(|| fnname.unraw());
let pyo3_path = get_pyo3_path(&options.pyo3_path);
let krate = get_pyo3_crate(&options.krate);
let cb_name = Ident::new(&format!("PyInit_{}", name), Span::call_site());
quote! {
@ -72,8 +71,8 @@ pub fn py_init(fnname: &Ident, options: PyModuleOptions, doc: PythonDoc) -> Toke
#[allow(non_snake_case)]
/// This autogenerated function is called by the python interpreter when importing
/// the module.
pub unsafe extern "C" fn #cb_name() -> *mut #pyo3_path::ffi::PyObject {
use #pyo3_path as _pyo3;
pub unsafe extern "C" fn #cb_name() -> *mut #krate::ffi::PyObject {
use #krate as _pyo3;
use _pyo3::derive_utils::ModuleDef;
static NAME: &str = concat!(stringify!(#name), "\0");
static DOC: &str = #doc;
@ -161,7 +160,7 @@ fn get_pyfn_attr(attrs: &mut Vec<syn::Attribute>) -> syn::Result<Option<PyFnArgs
}
enum PyModulePyO3Option {
PyO3Path(PyO3PathAttribute),
Crate(CrateAttribute),
Name(NameAttribute),
}
@ -171,7 +170,7 @@ impl Parse for PyModulePyO3Option {
if lookahead.peek(attributes::kw::name) {
input.parse().map(PyModulePyO3Option::Name)
} else if lookahead.peek(syn::Token![crate]) {
input.parse().map(PyModulePyO3Option::PyO3Path)
input.parse().map(PyModulePyO3Option::Crate)
} else {
Err(lookahead.error())
}

View File

@ -1,13 +1,13 @@
// Copyright (c) 2017-present PyO3 Project and Contributors
use crate::attributes::{
self, take_pyo3_options, NameAttribute, PyO3PathAttribute, TextSignatureAttribute,
self, take_pyo3_options, CrateAttribute, NameAttribute, TextSignatureAttribute,
};
use crate::deprecations::Deprecations;
use crate::konst::{ConstAttributes, ConstSpec};
use crate::pyimpl::{gen_default_slot_impls, gen_py_const, PyClassMethodsType};
use crate::pymethod::{impl_py_getter_def, impl_py_setter_def, PropertyType};
use crate::utils::{self, get_pyo3_path, unwrap_group, PythonDoc};
use crate::utils::{self, get_pyo3_crate, unwrap_group, PythonDoc};
use proc_macro2::{Span, TokenStream};
use quote::quote;
use syn::ext::IdentExt;
@ -188,12 +188,12 @@ impl PyClassArgs {
pub struct PyClassPyO3Options {
pub text_signature: Option<TextSignatureAttribute>,
pub deprecations: Deprecations,
pub pyo3_path: Option<PyO3PathAttribute>,
pub krate: Option<CrateAttribute>,
}
enum PyClassPyO3Option {
TextSignature(TextSignatureAttribute),
PyO3Path(PyO3PathAttribute),
Crate(CrateAttribute),
}
impl Parse for PyClassPyO3Option {
@ -202,7 +202,7 @@ impl Parse for PyClassPyO3Option {
if lookahead.peek(attributes::kw::text_signature) {
input.parse().map(PyClassPyO3Option::TextSignature)
} else if lookahead.peek(Token![crate]) {
input.parse().map(PyClassPyO3Option::PyO3Path)
input.parse().map(PyClassPyO3Option::Crate)
} else {
Err(lookahead.error())
}
@ -217,8 +217,8 @@ impl PyClassPyO3Options {
PyClassPyO3Option::TextSignature(text_signature) => {
options.set_text_signature(text_signature)?;
}
PyClassPyO3Option::PyO3Path(path) => {
options.set_pyo3_path(path)?;
PyClassPyO3Option::Crate(path) => {
options.set_crate(path)?;
}
}
}
@ -237,12 +237,12 @@ impl PyClassPyO3Options {
Ok(())
}
pub fn set_pyo3_path(&mut self, path: PyO3PathAttribute) -> syn::Result<()> {
pub fn set_crate(&mut self, path: CrateAttribute) -> syn::Result<()> {
ensure_spanned!(
self.pyo3_path.is_none(),
self.krate.is_none(),
path.0.span() => "`text_signature` may only be specified once"
);
self.pyo3_path = Some(path);
self.krate = Some(path);
Ok(())
}
}
@ -260,7 +260,7 @@ pub fn build_py_class(
.as_ref()
.map(|attr| (get_class_python_name(&class.ident, args), attr)),
);
let pyo3_path = get_pyo3_path(&options.pyo3_path);
let krate = get_pyo3_crate(&options.krate);
ensure_spanned!(
class.generics.params.is_empty(),
@ -297,7 +297,7 @@ pub fn build_py_class(
field_options,
methods_type,
options.deprecations,
pyo3_path,
krate,
)
}
@ -378,7 +378,7 @@ fn impl_class(
field_options: Vec<(&syn::Field, FieldPyO3Options)>,
methods_type: PyClassMethodsType,
deprecations: Deprecations,
pyo3_path: syn::Path,
krate: syn::Path,
) -> syn::Result<TokenStream> {
let pytypeinfo_impl = impl_pytypeinfo(cls, attr, Some(&deprecations));
@ -390,7 +390,7 @@ fn impl_class(
Ok(quote! {
const _: () = {
use #pyo3_path as _pyo3;
use #krate as _pyo3;
#pytypeinfo_impl
@ -439,8 +439,8 @@ fn impl_enum(
.as_ref()
.map(|attr| (get_class_python_name(&enum_.ident, args), attr)),
);
let pyo3_path = get_pyo3_path(&options.pyo3_path);
impl_enum_class(enum_name, args, variants, doc, methods_type, pyo3_path)
let krate = get_pyo3_crate(&options.krate);
impl_enum_class(enum_name, args, variants, doc, methods_type, krate)
}
fn impl_enum_class(
@ -449,7 +449,7 @@ fn impl_enum_class(
variants: Vec<PyClassEnumVariant>,
doc: PythonDoc,
methods_type: PyClassMethodsType,
pyo3_path: syn::Path,
krate: syn::Path,
) -> syn::Result<TokenStream> {
let pytypeinfo = impl_pytypeinfo(cls, args, None);
let pyclass_impls = PyClassImplsBuilder::new(cls, args, methods_type)
@ -480,7 +480,7 @@ fn impl_enum_class(
let default_impls = gen_default_slot_impls(cls, vec![default_repr_impl]);
Ok(quote! {
const _: () = {
use #pyo3_path as _pyo3;
use #krate as _pyo3;
#pytypeinfo

View File

@ -2,13 +2,13 @@
use crate::{
attributes::{
self, get_pyo3_options, take_attributes, take_pyo3_options, FromPyWithAttribute,
NameAttribute, PyO3PathAttribute, TextSignatureAttribute,
self, get_pyo3_options, take_attributes, take_pyo3_options, CrateAttribute,
FromPyWithAttribute, NameAttribute, TextSignatureAttribute,
},
deprecations::Deprecations,
method::{self, CallingConvention, FnArg},
pymethod::check_generic,
utils::{self, ensure_not_async_fn, get_pyo3_path},
utils::{self, ensure_not_async_fn, get_pyo3_crate},
};
use proc_macro2::{Span, TokenStream};
use quote::{format_ident, quote};
@ -239,7 +239,7 @@ pub struct PyFunctionOptions {
pub signature: Option<PyFunctionSignature>,
pub text_signature: Option<TextSignatureAttribute>,
pub deprecations: Deprecations,
pub pyo3_path: Option<PyO3PathAttribute>,
pub krate: Option<CrateAttribute>,
}
impl Parse for PyFunctionOptions {
@ -259,7 +259,7 @@ impl Parse for PyFunctionOptions {
}
} else if lookahead.peek(syn::Token![crate]) {
// TODO needs duplicate check?
options.pyo3_path = Some(input.parse()?);
options.krate = Some(input.parse()?);
} else {
// If not recognised attribute, this is "legacy" pyfunction syntax #[pyfunction(a, b)]
//
@ -278,7 +278,7 @@ pub enum PyFunctionOption {
PassModule(attributes::kw::pass_module),
Signature(PyFunctionSignature),
TextSignature(TextSignatureAttribute),
PyO3Path(PyO3PathAttribute),
Crate(CrateAttribute),
}
impl Parse for PyFunctionOption {
@ -293,7 +293,7 @@ impl Parse for PyFunctionOption {
} else if lookahead.peek(attributes::kw::text_signature) {
input.parse().map(PyFunctionOption::TextSignature)
} else if lookahead.peek(syn::Token![crate]) {
input.parse().map(PyFunctionOption::PyO3Path)
input.parse().map(PyFunctionOption::Crate)
} else {
Err(lookahead.error())
}
@ -336,12 +336,12 @@ impl PyFunctionOptions {
);
self.text_signature = Some(text_signature);
}
PyFunctionOption::PyO3Path(path) => {
PyFunctionOption::Crate(path) => {
ensure_spanned!(
self.pyo3_path.is_none(),
path.0.span() => "`pyo3_path` may only be specified once"
self.krate.is_none(),
path.0.span() => "`crate` may only be specified once"
);
self.pyo3_path = Some(path);
self.krate = Some(path);
}
}
}
@ -418,7 +418,7 @@ pub fn impl_wrap_pyfunction(
);
let function_wrapper_ident = function_wrapper_ident(&func.sig.ident);
let pyo3_path = get_pyo3_path(&options.pyo3_path);
let krate = get_pyo3_crate(&options.krate);
let spec = method::FnSpec {
tp: if options.pass_module.is_some() {
@ -435,7 +435,7 @@ pub fn impl_wrap_pyfunction(
doc,
deprecations: options.deprecations,
text_signature: options.text_signature,
pyo3_path: pyo3_path.clone(),
krate: krate.clone(),
};
let wrapper_ident = format_ident!("__pyo3_raw_{}", spec.name);
@ -446,9 +446,9 @@ pub fn impl_wrap_pyfunction(
#wrapper
pub(crate) fn #function_wrapper_ident<'a>(
args: impl ::std::convert::Into<#pyo3_path::derive_utils::PyFunctionArguments<'a>>
) -> #pyo3_path::PyResult<&'a #pyo3_path::types::PyCFunction> {
use #pyo3_path as _pyo3;
args: impl ::std::convert::Into<#krate::derive_utils::PyFunctionArguments<'a>>
) -> #krate::PyResult<&'a #krate::types::PyCFunction> {
use #krate as _pyo3;
_pyo3::types::PyCFunction::internal_new(#methoddef, args.into())
}
};

View File

@ -3,11 +3,11 @@
use std::collections::HashSet;
use crate::{
attributes::{take_pyo3_options, PyO3PathAttribute},
attributes::{take_pyo3_options, CrateAttribute},
konst::{ConstAttributes, ConstSpec},
pyfunction::PyFunctionOptions,
pymethod::{self, is_proto_method},
utils::get_pyo3_path,
utils::get_pyo3_crate,
};
use proc_macro2::TokenStream;
use pymethod::GeneratedPyMethod;
@ -26,14 +26,14 @@ pub enum PyClassMethodsType {
}
enum PyImplPyO3Option {
PyO3Path(PyO3PathAttribute),
Crate(CrateAttribute),
}
impl Parse for PyImplPyO3Option {
fn parse(input: ParseStream) -> Result<Self> {
let lookahead = input.lookahead1();
if lookahead.peek(syn::Token![crate]) {
input.parse().map(PyImplPyO3Option::PyO3Path)
input.parse().map(PyImplPyO3Option::Crate)
} else {
Err(lookahead.error())
}
@ -42,7 +42,7 @@ impl Parse for PyImplPyO3Option {
#[derive(Default)]
pub struct PyImplOptions {
pyo3_path: Option<PyO3PathAttribute>,
krate: Option<CrateAttribute>,
}
impl PyImplOptions {
@ -51,20 +51,20 @@ impl PyImplOptions {
for option in take_pyo3_options(attrs)? {
match option {
PyImplPyO3Option::PyO3Path(path) => options.set_pyo3_path(path)?,
PyImplPyO3Option::Crate(path) => options.set_crate(path)?,
}
}
Ok(options)
}
fn set_pyo3_path(&mut self, path: PyO3PathAttribute) -> Result<()> {
fn set_crate(&mut self, path: CrateAttribute) -> Result<()> {
ensure_spanned!(
self.pyo3_path.is_none(),
path.0.span() => "`pyo3_path` may only be specified once"
self.krate.is_none(),
path.0.span() => "`crate` may only be specified once"
);
self.pyo3_path = Some(path);
self.krate = Some(path);
Ok(())
}
}
@ -102,7 +102,7 @@ pub fn impl_methods(
match iimpl {
syn::ImplItem::Method(meth) => {
let mut fun_options = PyFunctionOptions::from_attrs(&mut meth.attrs)?;
fun_options.pyo3_path = fun_options.pyo3_path.or_else(|| options.pyo3_path.clone());
fun_options.krate = fun_options.krate.or_else(|| options.krate.clone());
match pymethod::gen_py_method(ty, &mut meth.sig, &mut meth.attrs, fun_options)? {
GeneratedPyMethod::Method(token_stream) => {
let attrs = get_cfg_attributes(&meth.attrs);
@ -148,7 +148,7 @@ pub fn impl_methods(
add_shared_proto_slots(ty, &mut proto_impls, implemented_proto_fragments);
let pyo3_path = get_pyo3_path(&options.pyo3_path);
let krate = get_pyo3_crate(&options.krate);
Ok(match methods_type {
PyClassMethodsType::Specialization => {
@ -157,7 +157,7 @@ pub fn impl_methods(
quote! {
const _: () = {
use #pyo3_path as _pyo3;
use #krate as _pyo3;
#(#trait_impls)*
@ -171,7 +171,7 @@ pub fn impl_methods(
let inventory = submit_methods_inventory(ty, methods, proto_impls);
quote! {
const _: () = {
use #pyo3_path as _pyo3;
use #krate as _pyo3;
#(#trait_impls)*

View File

@ -89,7 +89,7 @@ fn impl_proto_impl(
Ok(quote! {
const _: () = {
use ::pyo3 as _pyo3; // pyproto doesn't support specifying #[pyo3(pyo3_path)]
use ::pyo3 as _pyo3; // pyproto doesn't support specifying #[pyo3(crate)]
#trait_impls
#normal_methods
#protocol_methods

View File

@ -3,7 +3,7 @@ use proc_macro2::{Span, TokenStream};
use quote::ToTokens;
use syn::spanned::Spanned;
use crate::attributes::{PyO3PathAttribute, TextSignatureAttribute};
use crate::attributes::{CrateAttribute, TextSignatureAttribute};
/// Macro inspired by `anyhow::anyhow!` to create a compiler error with the given span.
macro_rules! err_spanned {
@ -191,7 +191,7 @@ pub(crate) fn replace_self(ty: &mut syn::Type, cls: &syn::Type) {
}
/// Extract the path to the pyo3 crate, or use the default (`::pyo3`).
pub(crate) fn get_pyo3_path(attr: &Option<PyO3PathAttribute>) -> syn::Path {
pub(crate) fn get_pyo3_crate(attr: &Option<CrateAttribute>) -> syn::Path {
attr.as_ref()
.map(|p| p.0.clone())
.unwrap_or_else(|| syn::parse_str("::pyo3").unwrap())