From b8e4467dc4111d64117c13e5abbf900a01b48850 Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Tue, 23 Nov 2021 21:21:28 +0100 Subject: [PATCH] pyo3_path, part 1: mechanical replacement `::pyo3` -> `_pyo3` --- pyo3-macros-backend/src/deprecations.rs | 2 +- pyo3-macros-backend/src/from_pyobject.rs | 36 +++--- pyo3-macros-backend/src/method.rs | 76 ++++++------ pyo3-macros-backend/src/module.rs | 6 +- pyo3-macros-backend/src/params.rs | 12 +- pyo3-macros-backend/src/pyclass.rs | 140 +++++++++++------------ pyo3-macros-backend/src/pyfunction.rs | 6 +- pyo3-macros-backend/src/pyimpl.rs | 30 ++--- pyo3-macros-backend/src/pymethod.rs | 120 +++++++++---------- pyo3-macros-backend/src/pyproto.rs | 34 +++--- 10 files changed, 231 insertions(+), 231 deletions(-) diff --git a/pyo3-macros-backend/src/deprecations.rs b/pyo3-macros-backend/src/deprecations.rs index 4bf3d62467b..3d5fe878510 100644 --- a/pyo3-macros-backend/src/deprecations.rs +++ b/pyo3-macros-backend/src/deprecations.rs @@ -33,7 +33,7 @@ impl ToTokens for Deprecations { let ident = deprecation.ident(*span); quote_spanned!( *span => - let _ = ::pyo3::impl_::deprecations::#ident; + let _ = _pyo3::impl_::deprecations::#ident; ) .to_tokens(tokens) } diff --git a/pyo3-macros-backend/src/from_pyobject.rs b/pyo3-macros-backend/src/from_pyobject.rs index 5f4811ebd31..ef9d971a58c 100644 --- a/pyo3-macros-backend/src/from_pyobject.rs +++ b/pyo3-macros-backend/src/from_pyobject.rs @@ -55,14 +55,14 @@ impl<'a> Enum<'a> { for (i, var) in self.variants.iter().enumerate() { let struct_derive = var.build(); let ext = quote!( - let maybe_ret = || -> ::pyo3::PyResult { + let maybe_ret = || -> _pyo3::PyResult { #struct_derive }(); match maybe_ret { ok @ ::std::result::Result::Ok(_) => return ok, ::std::result::Result::Err(inner) => { - let py = ::pyo3::PyNativeType::py(obj); + let py = _pyo3::PyNativeType::py(obj); err_reasons.push_str(&::std::format!("{}\n", inner.instance(py).str()?)); } } @@ -82,7 +82,7 @@ impl<'a> Enum<'a> { #ty_name, #error_names, &err_reasons); - ::std::result::Result::Err(::pyo3::exceptions::PyTypeError::new_err(err_msg)) + ::std::result::Result::Err(_pyo3::exceptions::PyTypeError::new_err(err_msg)) ) } } @@ -207,8 +207,8 @@ impl<'a> Container<'a> { ); quote!( ::std::result::Result::Ok(#self_ty{#ident: obj.extract().map_err(|inner| { - let py = ::pyo3::PyNativeType::py(obj); - let new_err = ::pyo3::exceptions::PyTypeError::new_err(#error_msg); + let py = _pyo3::PyNativeType::py(obj); + let new_err = _pyo3::exceptions::PyTypeError::new_err(#error_msg); new_err.set_cause(py, ::std::option::Option::Some(inner)); new_err })?}) @@ -222,11 +222,11 @@ impl<'a> Container<'a> { }; quote!( ::std::result::Result::Ok(#self_ty(obj.extract().map_err(|inner| { - let py = ::pyo3::PyNativeType::py(obj); + let py = _pyo3::PyNativeType::py(obj); let err_msg = ::std::format!("{}: {}", #error_msg, inner.instance(py).str().unwrap()); - ::pyo3::exceptions::PyTypeError::new_err(err_msg) + _pyo3::exceptions::PyTypeError::new_err(err_msg) })?)) ) } @@ -238,9 +238,9 @@ impl<'a> Container<'a> { for i in 0..len { let error_msg = format!("failed to extract field {}.{}", quote!(#self_ty), i); fields.push(quote!( - s.get_item(#i).and_then(::pyo3::types::PyAny::extract).map_err(|inner| { - let py = ::pyo3::PyNativeType::py(obj); - let new_err = ::pyo3::exceptions::PyTypeError::new_err(#error_msg); + s.get_item(#i).and_then(_pyo3::types::PyAny::extract).map_err(|inner| { + let py = _pyo3::PyNativeType::py(obj); + let new_err = _pyo3::exceptions::PyTypeError::new_err(#error_msg); new_err.set_cause(py, ::std::option::Option::Some(inner)); new_err })?)); @@ -255,9 +255,9 @@ impl<'a> Container<'a> { quote!("") }; quote!( - let s = <::pyo3::types::PyTuple as ::pyo3::conversion::PyTryFrom>::try_from(obj)?; + let s = <_pyo3::types::PyTuple as _pyo3::conversion::PyTryFrom>::try_from(obj)?; if s.len() != #len { - return ::std::result::Result::Err(::pyo3::exceptions::PyValueError::new_err(#msg)) + return ::std::result::Result::Err(_pyo3::exceptions::PyValueError::new_err(#msg)) } ::std::result::Result::Ok(#self_ty(#fields)) ) @@ -279,15 +279,15 @@ impl<'a> Container<'a> { let extractor = match &attrs.from_py_with { None => quote!( #get_field.extract().map_err(|inner| { - let py = ::pyo3::PyNativeType::py(obj); - let new_err = ::pyo3::exceptions::PyTypeError::new_err(#conversion_error_msg); + let py = _pyo3::PyNativeType::py(obj); + let new_err = _pyo3::exceptions::PyTypeError::new_err(#conversion_error_msg); new_err.set_cause(py, ::std::option::Option::Some(inner)); new_err })?), Some(FromPyWithAttribute(expr_path)) => quote! ( #expr_path(#get_field).map_err(|inner| { - let py = ::pyo3::PyNativeType::py(obj); - let new_err = ::pyo3::exceptions::PyTypeError::new_err(#conversion_error_msg); + let py = _pyo3::PyNativeType::py(obj); + let new_err = _pyo3::exceptions::PyTypeError::new_err(#conversion_error_msg); new_err.set_cause(py, ::std::option::Option::Some(inner)); new_err })? @@ -521,8 +521,8 @@ pub fn build_derive_from_pyobject(tokens: &DeriveInput) -> Result { let ident = &tokens.ident; Ok(quote!( #[automatically_derived] - impl#trait_generics ::pyo3::FromPyObject<#lt_param> for #ident#generics #where_clause { - fn extract(obj: &#lt_param ::pyo3::PyAny) -> ::pyo3::PyResult { + impl#trait_generics _pyo3::FromPyObject<#lt_param> for #ident#generics #where_clause { + fn extract(obj: &#lt_param _pyo3::PyAny) -> _pyo3::PyResult { #derives } } diff --git a/pyo3-macros-backend/src/method.rs b/pyo3-macros-backend/src/method.rs index 6a7b8432d9f..885c59e0525 100644 --- a/pyo3-macros-backend/src/method.rs +++ b/pyo3-macros-backend/src/method.rs @@ -106,12 +106,12 @@ impl FnType { } FnType::FnClass => { quote! { - let _slf = ::pyo3::types::PyType::from_type_ptr(_py, _slf as *mut ::pyo3::ffi::PyTypeObject); + let _slf = _pyo3::types::PyType::from_type_ptr(_py, _slf as *mut _pyo3::ffi::PyTypeObject); } } FnType::FnModule => { quote! { - let _slf = _py.from_borrowed_ptr::<::pyo3::types::PyModule>(_slf); + let _slf = _py.from_borrowed_ptr::<_pyo3::types::PyModule>(_slf); } } } @@ -141,13 +141,13 @@ impl SelfType { pub fn receiver(&self, cls: &syn::Type, error_mode: ExtractErrorMode) -> TokenStream { let cell = match error_mode { ExtractErrorMode::Raise => { - quote! { _py.from_borrowed_ptr::<::pyo3::PyAny>(_slf).downcast::<::pyo3::PyCell<#cls>>()? } + quote! { _py.from_borrowed_ptr::<_pyo3::PyAny>(_slf).downcast::<_pyo3::PyCell<#cls>>()? } } ExtractErrorMode::NotImplemented => { quote! { - match _py.from_borrowed_ptr::<::pyo3::PyAny>(_slf).downcast::<::pyo3::PyCell<#cls>>() { + match _py.from_borrowed_ptr::<_pyo3::PyAny>(_slf).downcast::<_pyo3::PyCell<#cls>>() { ::std::result::Result::Ok(cell) => cell, - ::std::result::Result::Err(_) => return ::pyo3::callback::convert(_py, _py.NotImplemented()), + ::std::result::Result::Err(_) => return _pyo3::callback::convert(_py, _py.NotImplemented()), } } } @@ -471,17 +471,17 @@ impl<'a> FnSpec<'a> { quote!(#func_name) }; let rust_call = - quote! { ::pyo3::callback::convert(#py, #rust_name(#self_arg #(#arg_names),*)) }; + quote! { _pyo3::callback::convert(#py, #rust_name(#self_arg #(#arg_names),*)) }; Ok(match self.convention { CallingConvention::Noargs => { quote! { unsafe extern "C" fn #ident ( - _slf: *mut ::pyo3::ffi::PyObject, - _args: *mut ::pyo3::ffi::PyObject, - ) -> *mut ::pyo3::ffi::PyObject + _slf: *mut _pyo3::ffi::PyObject, + _args: *mut _pyo3::ffi::PyObject, + ) -> *mut _pyo3::ffi::PyObject { #deprecations - ::pyo3::callback::handle_panic(|#py| { + _pyo3::callback::handle_panic(|#py| { #self_conversion #rust_call }) @@ -492,17 +492,17 @@ 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::ffi::PyObject, - _args: *const *mut ::pyo3::ffi::PyObject, - _nargs: ::pyo3::ffi::Py_ssize_t, - _kwnames: *mut ::pyo3::ffi::PyObject) -> *mut ::pyo3::ffi::PyObject + _slf: *mut _pyo3::ffi::PyObject, + _args: *const *mut _pyo3::ffi::PyObject, + _nargs: _pyo3::ffi::Py_ssize_t, + _kwnames: *mut _pyo3::ffi::PyObject) -> *mut _pyo3::ffi::PyObject { #deprecations - ::pyo3::callback::handle_panic(|#py| { + _pyo3::callback::handle_panic(|#py| { #self_conversion - let _kwnames: ::std::option::Option<&::pyo3::types::PyTuple> = #py.from_borrowed_ptr_or_opt(_kwnames); + let _kwnames: ::std::option::Option<&_pyo3::types::PyTuple> = #py.from_borrowed_ptr_or_opt(_kwnames); // Safety: &PyAny has the same memory layout as `*mut ffi::PyObject` - let _args = _args as *const &::pyo3::PyAny; + let _args = _args as *const &_pyo3::PyAny; let _kwargs = if let ::std::option::Option::Some(kwnames) = _kwnames { ::std::slice::from_raw_parts(_args.offset(_nargs), kwnames.len()) } else { @@ -519,15 +519,15 @@ 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::ffi::PyObject, - _args: *mut ::pyo3::ffi::PyObject, - _kwargs: *mut ::pyo3::ffi::PyObject) -> *mut ::pyo3::ffi::PyObject + _slf: *mut _pyo3::ffi::PyObject, + _args: *mut _pyo3::ffi::PyObject, + _kwargs: *mut _pyo3::ffi::PyObject) -> *mut _pyo3::ffi::PyObject { #deprecations - ::pyo3::callback::handle_panic(|#py| { + _pyo3::callback::handle_panic(|#py| { #self_conversion - let _args = #py.from_borrowed_ptr::<::pyo3::types::PyTuple>(_args); - let _kwargs: ::std::option::Option<&::pyo3::types::PyDict> = #py.from_borrowed_ptr_or_opt(_kwargs); + let _args = #py.from_borrowed_ptr::<_pyo3::types::PyTuple>(_args); + let _kwargs: ::std::option::Option<&_pyo3::types::PyDict> = #py.from_borrowed_ptr_or_opt(_kwargs); #arg_convert_and_rust_call }) @@ -539,20 +539,20 @@ 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::ffi::PyTypeObject, - _args: *mut ::pyo3::ffi::PyObject, - _kwargs: *mut ::pyo3::ffi::PyObject) -> *mut ::pyo3::ffi::PyObject + subtype: *mut _pyo3::ffi::PyTypeObject, + _args: *mut _pyo3::ffi::PyObject, + _kwargs: *mut _pyo3::ffi::PyObject) -> *mut _pyo3::ffi::PyObject { #deprecations - use ::pyo3::callback::IntoPyCallbackOutput; - ::pyo3::callback::handle_panic(|#py| { - let _args = #py.from_borrowed_ptr::<::pyo3::types::PyTuple>(_args); - let _kwargs: ::std::option::Option<&::pyo3::types::PyDict> = #py.from_borrowed_ptr_or_opt(_kwargs); + use _pyo3::callback::IntoPyCallbackOutput; + _pyo3::callback::handle_panic(|#py| { + let _args = #py.from_borrowed_ptr::<_pyo3::types::PyTuple>(_args); + let _kwargs: ::std::option::Option<&_pyo3::types::PyDict> = #py.from_borrowed_ptr_or_opt(_kwargs); let result = #arg_convert_and_rust_call; - let initializer: ::pyo3::PyClassInitializer::<#cls> = result.convert(#py)?; + let initializer: _pyo3::PyClassInitializer::<#cls> = result.convert(#py)?; let cell = initializer.create_cell_from_subtype(#py, subtype)?; - ::std::result::Result::Ok(cell as *mut ::pyo3::ffi::PyObject) + ::std::result::Result::Ok(cell as *mut _pyo3::ffi::PyObject) }) } } @@ -567,23 +567,23 @@ impl<'a> FnSpec<'a> { let doc = &self.doc; match self.convention { CallingConvention::Noargs => quote! { - ::pyo3::class::methods::PyMethodDef::noargs( + _pyo3::class::methods::PyMethodDef::noargs( #python_name, - ::pyo3::class::methods::PyCFunction(#wrapper), + _pyo3::class::methods::PyCFunction(#wrapper), #doc, ) }, CallingConvention::Fastcall => quote! { - ::pyo3::class::methods::PyMethodDef::fastcall_cfunction_with_keywords( + _pyo3::class::methods::PyMethodDef::fastcall_cfunction_with_keywords( #python_name, - ::pyo3::class::methods::PyCFunctionFastWithKeywords(#wrapper), + _pyo3::class::methods::PyCFunctionFastWithKeywords(#wrapper), #doc, ) }, CallingConvention::Varargs => quote! { - ::pyo3::class::methods::PyMethodDef::cfunction_with_keywords( + _pyo3::class::methods::PyMethodDef::cfunction_with_keywords( #python_name, - ::pyo3::class::methods::PyCFunctionWithKeywords(#wrapper), + _pyo3::class::methods::PyCFunctionWithKeywords(#wrapper), #doc, ) }, diff --git a/pyo3-macros-backend/src/module.rs b/pyo3-macros-backend/src/module.rs index 5adc02d4c63..b6013003ba0 100644 --- a/pyo3-macros-backend/src/module.rs +++ b/pyo3-macros-backend/src/module.rs @@ -55,13 +55,13 @@ 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::ffi::PyObject { - use ::pyo3::derive_utils::ModuleDef; + pub unsafe extern "C" fn #cb_name() -> *mut _pyo3::ffi::PyObject { + use _pyo3::derive_utils::ModuleDef; static NAME: &str = concat!(stringify!(#name), "\0"); static DOC: &str = #doc; static MODULE_DEF: ModuleDef = unsafe { ModuleDef::new(NAME, DOC) }; - ::pyo3::callback::handle_panic(|_py| { MODULE_DEF.make_module(_py, #fnname) }) + _pyo3::callback::handle_panic(|_py| { MODULE_DEF.make_module(_py, #fnname) }) } } } diff --git a/pyo3-macros-backend/src/params.rs b/pyo3-macros-backend/src/params.rs index 1bbbb4727d8..9a4d2996180 100644 --- a/pyo3-macros-backend/src/params.rs +++ b/pyo3-macros-backend/src/params.rs @@ -93,7 +93,7 @@ pub fn impl_arg_params( if kwonly { keyword_only_parameters.push(quote! { - ::pyo3::derive_utils::KeywordOnlyParameterDescription { + _pyo3::derive_utils::KeywordOnlyParameterDescription { name: #name, required: #required, } @@ -128,7 +128,7 @@ pub fn impl_arg_params( let (accept_args, accept_kwargs) = accept_args_kwargs(&spec.attrs); let cls_name = if let Some(cls) = self_ { - quote! { ::std::option::Option::Some(<#cls as ::pyo3::type_object::PyTypeInfo>::NAME) } + quote! { ::std::option::Option::Some(<#cls as _pyo3::type_object::PyTypeInfo>::NAME) } } else { quote! { ::std::option::Option::None } }; @@ -155,7 +155,7 @@ pub fn impl_arg_params( // create array of arguments, and then parse Ok(quote! {{ - const DESCRIPTION: ::pyo3::derive_utils::FunctionDescription = ::pyo3::derive_utils::FunctionDescription { + const DESCRIPTION: _pyo3::derive_utils::FunctionDescription = _pyo3::derive_utils::FunctionDescription { cls_name: #cls_name, func_name: stringify!(#python_name), positional_parameter_names: &[#(#positional_parameter_names),*], @@ -206,7 +206,7 @@ fn impl_arg_param( let ty = arg.ty; let name = arg.name; let transform_error = quote! { - |e| ::pyo3::derive_utils::argument_extraction_error(#py, stringify!(#name), e) + |e| _pyo3::derive_utils::argument_extraction_error(#py, stringify!(#name), e) }; if is_args(&spec.attrs, name) { @@ -275,7 +275,7 @@ fn impl_arg_param( let (target_ty, borrow_tmp) = if arg.optional.is_some() { // Get Option<&T> from Option> ( - quote_arg_span! { ::std::option::Option<<#tref as ::pyo3::derive_utils::ExtractExt<'_>>::Target> }, + quote_arg_span! { ::std::option::Option<<#tref as _pyo3::derive_utils::ExtractExt<'_>>::Target> }, if mut_.is_some() { quote_arg_span! { _tmp.as_deref_mut() } } else { @@ -285,7 +285,7 @@ fn impl_arg_param( } else { // Get &T from PyRef ( - quote_arg_span! { <#tref as ::pyo3::derive_utils::ExtractExt<'_>>::Target }, + quote_arg_span! { <#tref as _pyo3::derive_utils::ExtractExt<'_>>::Target }, quote_arg_span! { &#mut_ *_tmp }, ) }; diff --git a/pyo3-macros-backend/src/pyclass.rs b/pyo3-macros-backend/src/pyclass.rs index 9bafc6b61dc..e4b6127eeb8 100644 --- a/pyo3-macros-backend/src/pyclass.rs +++ b/pyo3-macros-backend/src/pyclass.rs @@ -58,7 +58,7 @@ impl PyClassArgs { freelist: None, name: None, module: None, - base: parse_quote! { ::pyo3::PyAny }, + base: parse_quote! { _pyo3::PyAny }, has_dict: false, has_weaklist: false, is_gc: false, @@ -454,11 +454,11 @@ fn unit_variants_as_descriptors<'a>( .map(|var| gen_py_const(&cls_type, &variant_to_attribute(var))); quote! { - impl ::pyo3::class::impl_::PyClassDescriptors<#cls> - for ::pyo3::class::impl_::PyClassImplCollector<#cls> + impl _pyo3::class::impl_::PyClassDescriptors<#cls> + for _pyo3::class::impl_::PyClassImplCollector<#cls> { - fn py_class_descriptors(self) -> &'static [::pyo3::class::methods::PyMethodDefType] { - static METHODS: &[::pyo3::class::methods::PyMethodDefType] = &[#(#py_methods),*]; + fn py_class_descriptors(self) -> &'static [_pyo3::class::methods::PyMethodDefType] { + static METHODS: &[_pyo3::class::methods::PyMethodDefType] = &[#(#py_methods),*]; METHODS } } @@ -517,11 +517,11 @@ fn impl_descriptors( .collect::>()?; Ok(quote! { - impl ::pyo3::class::impl_::PyClassDescriptors<#cls> - for ::pyo3::class::impl_::PyClassImplCollector<#cls> + impl _pyo3::class::impl_::PyClassDescriptors<#cls> + for _pyo3::class::impl_::PyClassImplCollector<#cls> { - fn py_class_descriptors(self) -> &'static [::pyo3::class::methods::PyMethodDefType] { - static METHODS: &[::pyo3::class::methods::PyMethodDefType] = &[#(#py_methods),*]; + fn py_class_descriptors(self) -> &'static [_pyo3::class::methods::PyMethodDefType] { + static METHODS: &[_pyo3::class::methods::PyMethodDefType] = &[#(#py_methods),*]; METHODS } } @@ -542,17 +542,17 @@ fn impl_pytypeinfo( }; quote! { - unsafe impl ::pyo3::type_object::PyTypeInfo for #cls { - type AsRefTarget = ::pyo3::PyCell; + unsafe impl _pyo3::type_object::PyTypeInfo for #cls { + type AsRefTarget = _pyo3::PyCell; const NAME: &'static str = #cls_name; const MODULE: ::std::option::Option<&'static str> = #module; #[inline] - fn type_object_raw(py: ::pyo3::Python<'_>) -> *mut ::pyo3::ffi::PyTypeObject { + fn type_object_raw(py: _pyo3::Python<'_>) -> *mut _pyo3::ffi::PyTypeObject { #deprecations - use ::pyo3::type_object::LazyStaticType; + use _pyo3::type_object::LazyStaticType; static TYPE_OBJECT: LazyStaticType = LazyStaticType::new(); TYPE_OBJECT.get_or_init::(py) } @@ -606,29 +606,29 @@ impl<'a> PyClassImplsBuilder<'a> { let cls = self.cls; let attr = self.attr; let dict = if attr.has_dict { - quote! { ::pyo3::pyclass_slots::PyClassDictSlot } + quote! { _pyo3::pyclass_slots::PyClassDictSlot } } else if attr.has_extends { - quote! { ::Dict } + quote! { ::Dict } } else { - quote! { ::pyo3::pyclass_slots::PyClassDummySlot } + quote! { _pyo3::pyclass_slots::PyClassDummySlot } }; // insert space for weak ref let weakref = if attr.has_weaklist { - quote! { ::pyo3::pyclass_slots::PyClassWeakRefSlot } + quote! { _pyo3::pyclass_slots::PyClassWeakRefSlot } } else if attr.has_extends { - quote! { ::WeakRef } + quote! { ::WeakRef } } else { - quote! { ::pyo3::pyclass_slots::PyClassDummySlot } + quote! { _pyo3::pyclass_slots::PyClassDummySlot } }; let base_nativetype = if attr.has_extends { - quote! { ::BaseNativeType } + quote! { ::BaseNativeType } } else { - quote! { ::pyo3::PyAny } + quote! { _pyo3::PyAny } }; quote! { - impl ::pyo3::PyClass for #cls { + impl _pyo3::PyClass for #cls { type Dict = #dict; type WeakRef = #weakref; type BaseNativeType = #base_nativetype; @@ -638,14 +638,14 @@ impl<'a> PyClassImplsBuilder<'a> { fn impl_extractext(&self) -> TokenStream { let cls = self.cls; quote! { - impl<'a> ::pyo3::derive_utils::ExtractExt<'a> for &'a #cls + impl<'a> _pyo3::derive_utils::ExtractExt<'a> for &'a #cls { - type Target = ::pyo3::PyRef<'a, #cls>; + type Target = _pyo3::PyRef<'a, #cls>; } - impl<'a> ::pyo3::derive_utils::ExtractExt<'a> for &'a mut #cls + impl<'a> _pyo3::derive_utils::ExtractExt<'a> for &'a mut #cls { - type Target = ::pyo3::PyRefMut<'a, #cls>; + type Target = _pyo3::PyRefMut<'a, #cls>; } } } @@ -656,9 +656,9 @@ impl<'a> PyClassImplsBuilder<'a> { // If #cls is not extended type, we allow Self->PyObject conversion if !attr.has_extends { quote! { - impl ::pyo3::IntoPy<::pyo3::PyObject> for #cls { - fn into_py(self, py: ::pyo3::Python) -> ::pyo3::PyObject { - ::pyo3::IntoPy::into_py(::pyo3::Py::new(py, self).unwrap(), py) + impl _pyo3::IntoPy<_pyo3::PyObject> for #cls { + fn into_py(self, py: _pyo3::Python) -> _pyo3::PyObject { + _pyo3::IntoPy::into_py(_pyo3::Py::new(py, self).unwrap(), py) } } } @@ -675,13 +675,13 @@ impl<'a> PyClassImplsBuilder<'a> { let is_subclass = self.attr.has_extends; let thread_checker = if self.attr.has_unsendable { - quote! { ::pyo3::class::impl_::ThreadCheckerImpl<#cls> } + quote! { _pyo3::class::impl_::ThreadCheckerImpl<#cls> } } else if self.attr.has_extends { quote! { - ::pyo3::class::impl_::ThreadCheckerInherited<#cls, <#cls as ::pyo3::class::impl_::PyClassImpl>::BaseType> + _pyo3::class::impl_::ThreadCheckerInherited<#cls, <#cls as _pyo3::class::impl_::PyClassImpl>::BaseType> } } else { - quote! { ::pyo3::class::impl_::ThreadCheckerStub<#cls> } + quote! { _pyo3::class::impl_::ThreadCheckerStub<#cls> } }; let (for_each_py_method, methods_protos, inventory, inventory_class) = match self @@ -701,13 +701,13 @@ impl<'a> PyClassImplsBuilder<'a> { ); ( quote! { - for inventory in ::pyo3::inventory::iter::<::Inventory>() { - visitor(::pyo3::class::impl_::PyClassInventory::methods(inventory)); + for inventory in _pyo3::inventory::iter::<::Inventory>() { + visitor(_pyo3::class::impl_::PyClassInventory::methods(inventory)); } }, quote! { - for inventory in ::pyo3::inventory::iter::<::Inventory>() { - visitor(::pyo3::class::impl_::PyClassInventory::slots(inventory)); + for inventory in _pyo3::inventory::iter::<::Inventory>() { + visitor(_pyo3::class::impl_::PyClassInventory::slots(inventory)); } }, Some(quote! { type Inventory = #inventory_class_name; }), @@ -716,19 +716,19 @@ impl<'a> PyClassImplsBuilder<'a> { } }; quote! { - impl ::pyo3::class::impl_::PyClassImpl for #cls { + impl _pyo3::class::impl_::PyClassImpl for #cls { const DOC: &'static str = #doc; const IS_GC: bool = #is_gc; const IS_BASETYPE: bool = #is_basetype; const IS_SUBCLASS: bool = #is_subclass; - type Layout = ::pyo3::PyCell; + type Layout = _pyo3::PyCell; type BaseType = #base; type ThreadChecker = #thread_checker; #inventory - fn for_each_method_def(visitor: &mut dyn ::std::ops::FnMut(&[::pyo3::class::PyMethodDefType])) { - use ::pyo3::class::impl_::*; + fn for_each_method_def(visitor: &mut dyn ::std::ops::FnMut(&[_pyo3::class::PyMethodDefType])) { + use _pyo3::class::impl_::*; let collector = PyClassImplCollector::::new(); #for_each_py_method; visitor(collector.py_class_descriptors()); @@ -738,25 +738,25 @@ impl<'a> PyClassImplsBuilder<'a> { visitor(collector.mapping_protocol_methods()); visitor(collector.number_protocol_methods()); } - fn get_new() -> ::std::option::Option<::pyo3::ffi::newfunc> { - use ::pyo3::class::impl_::*; + fn get_new() -> ::std::option::Option<_pyo3::ffi::newfunc> { + use _pyo3::class::impl_::*; let collector = PyClassImplCollector::::new(); collector.new_impl() } - fn get_alloc() -> ::std::option::Option<::pyo3::ffi::allocfunc> { - use ::pyo3::class::impl_::*; + fn get_alloc() -> ::std::option::Option<_pyo3::ffi::allocfunc> { + use _pyo3::class::impl_::*; let collector = PyClassImplCollector::::new(); collector.alloc_impl() } - fn get_free() -> ::std::option::Option<::pyo3::ffi::freefunc> { - use ::pyo3::class::impl_::*; + fn get_free() -> ::std::option::Option<_pyo3::ffi::freefunc> { + use _pyo3::class::impl_::*; let collector = PyClassImplCollector::::new(); collector.free_impl() } - fn for_each_proto_slot(visitor: &mut dyn ::std::ops::FnMut(&[::pyo3::ffi::PyType_Slot])) { + fn for_each_proto_slot(visitor: &mut dyn ::std::ops::FnMut(&[_pyo3::ffi::PyType_Slot])) { // Implementation which uses dtolnay specialization to load all slots. - use ::pyo3::class::impl_::*; + use _pyo3::class::impl_::*; let collector = PyClassImplCollector::::new(); visitor(collector.object_protocol_slots()); visitor(collector.number_protocol_slots()); @@ -770,8 +770,8 @@ impl<'a> PyClassImplsBuilder<'a> { #methods_protos } - fn get_buffer() -> ::std::option::Option<&'static ::pyo3::class::impl_::PyBufferProcs> { - use ::pyo3::class::impl_::*; + fn get_buffer() -> ::std::option::Option<&'static _pyo3::class::impl_::PyBufferProcs> { + use _pyo3::class::impl_::*; let collector = PyClassImplCollector::::new(); collector.buffer_procs() } @@ -786,31 +786,31 @@ impl<'a> PyClassImplsBuilder<'a> { self.attr.freelist.as_ref().map_or(quote!{}, |freelist| { quote! { - impl ::pyo3::class::impl_::PyClassWithFreeList for #cls { + impl _pyo3::class::impl_::PyClassWithFreeList for #cls { #[inline] - fn get_free_list(_py: ::pyo3::Python<'_>) -> &mut ::pyo3::impl_::freelist::FreeList<*mut ::pyo3::ffi::PyObject> { - static mut FREELIST: *mut ::pyo3::impl_::freelist::FreeList<*mut ::pyo3::ffi::PyObject> = 0 as *mut _; + fn get_free_list(_py: _pyo3::Python<'_>) -> &mut _pyo3::impl_::freelist::FreeList<*mut _pyo3::ffi::PyObject> { + static mut FREELIST: *mut _pyo3::impl_::freelist::FreeList<*mut _pyo3::ffi::PyObject> = 0 as *mut _; unsafe { if FREELIST.is_null() { FREELIST = ::std::boxed::Box::into_raw(::std::boxed::Box::new( - ::pyo3::impl_::freelist::FreeList::with_capacity(#freelist))); + _pyo3::impl_::freelist::FreeList::with_capacity(#freelist))); } &mut *FREELIST } } } - impl ::pyo3::class::impl_::PyClassAllocImpl<#cls> for ::pyo3::class::impl_::PyClassImplCollector<#cls> { + impl _pyo3::class::impl_::PyClassAllocImpl<#cls> for _pyo3::class::impl_::PyClassImplCollector<#cls> { #[inline] - fn alloc_impl(self) -> ::std::option::Option<::pyo3::ffi::allocfunc> { - ::std::option::Option::Some(::pyo3::class::impl_::alloc_with_freelist::<#cls>) + fn alloc_impl(self) -> ::std::option::Option<_pyo3::ffi::allocfunc> { + ::std::option::Option::Some(_pyo3::class::impl_::alloc_with_freelist::<#cls>) } } - impl ::pyo3::class::impl_::PyClassFreeImpl<#cls> for ::pyo3::class::impl_::PyClassImplCollector<#cls> { + impl _pyo3::class::impl_::PyClassFreeImpl<#cls> for _pyo3::class::impl_::PyClassImplCollector<#cls> { #[inline] - fn free_impl(self) -> ::std::option::Option<::pyo3::ffi::freefunc> { - ::std::option::Option::Some(::pyo3::class::impl_::free_with_freelist::<#cls>) + fn free_impl(self) -> ::std::option::Option<_pyo3::ffi::freefunc> { + ::std::option::Option::Some(_pyo3::class::impl_::free_with_freelist::<#cls>) } } } @@ -825,9 +825,9 @@ impl<'a> PyClassImplsBuilder<'a> { let closure_token = syn::Ident::new(&closure_name, Span::call_site()); quote! { fn #closure_token() { - use ::pyo3::class; + use _pyo3::class; - fn _assert_implements_protocol<'p, T: ::pyo3::class::PyGCProtocol<'p>>() {} + fn _assert_implements_protocol<'p, T: _pyo3::class::PyGCProtocol<'p>>() {} _assert_implements_protocol::<#cls>(); } } @@ -841,23 +841,23 @@ fn define_inventory_class(inventory_class_name: &syn::Ident) -> TokenStream { quote! { #[doc(hidden)] pub struct #inventory_class_name { - methods: &'static [::pyo3::class::PyMethodDefType], - slots: &'static [::pyo3::ffi::PyType_Slot], + methods: &'static [_pyo3::class::PyMethodDefType], + slots: &'static [_pyo3::ffi::PyType_Slot], } impl #inventory_class_name { const fn new( - methods: &'static [::pyo3::class::PyMethodDefType], - slots: &'static [::pyo3::ffi::PyType_Slot], + methods: &'static [_pyo3::class::PyMethodDefType], + slots: &'static [_pyo3::ffi::PyType_Slot], ) -> Self { Self { methods, slots } } } - impl ::pyo3::class::impl_::PyClassInventory for #inventory_class_name { - fn methods(&'static self) -> &'static [::pyo3::class::PyMethodDefType] { + impl _pyo3::class::impl_::PyClassInventory for #inventory_class_name { + fn methods(&'static self) -> &'static [_pyo3::class::PyMethodDefType] { self.methods } - fn slots(&'static self) -> &'static [::pyo3::ffi::PyType_Slot] { + fn slots(&'static self) -> &'static [_pyo3::ffi::PyType_Slot] { self.slots } } @@ -866,6 +866,6 @@ fn define_inventory_class(inventory_class_name: &syn::Ident) -> TokenStream { unsafe impl ::std::marker::Send for #inventory_class_name {} unsafe impl ::std::marker::Sync for #inventory_class_name {} - ::pyo3::inventory::collect!(#inventory_class_name); + _pyo3::inventory::collect!(#inventory_class_name); } } diff --git a/pyo3-macros-backend/src/pyfunction.rs b/pyo3-macros-backend/src/pyfunction.rs index 87e8ffda1a9..b6e2c0faa1d 100644 --- a/pyo3-macros-backend/src/pyfunction.rs +++ b/pyo3-macros-backend/src/pyfunction.rs @@ -435,9 +435,9 @@ pub fn impl_wrap_pyfunction( let wrapped_pyfunction = quote! { #wrapper pub(crate) fn #function_wrapper_ident<'a>( - args: impl ::std::convert::Into<::pyo3::derive_utils::PyFunctionArguments<'a>> - ) -> ::pyo3::PyResult<&'a ::pyo3::types::PyCFunction> { - ::pyo3::types::PyCFunction::internal_new(#methoddef, args.into()) + args: impl ::std::convert::Into<_pyo3::derive_utils::PyFunctionArguments<'a>> + ) -> _pyo3::PyResult<&'a _pyo3::types::PyCFunction> { + _pyo3::types::PyCFunction::internal_new(#methoddef, args.into()) } }; Ok((function_wrapper_ident, wrapped_pyfunction)) diff --git a/pyo3-macros-backend/src/pyimpl.rs b/pyo3-macros-backend/src/pyimpl.rs index 33aa9749f4e..94add037f69 100644 --- a/pyo3-macros-backend/src/pyimpl.rs +++ b/pyo3-macros-backend/src/pyimpl.rs @@ -124,13 +124,13 @@ pub fn gen_py_const(cls: &syn::Type, spec: &ConstSpec) -> TokenStream { let deprecations = &spec.attributes.deprecations; let python_name = &spec.null_terminated_python_name(); quote! { - ::pyo3::class::PyMethodDefType::ClassAttribute({ - ::pyo3::class::PyClassAttributeDef::new( + _pyo3::class::PyMethodDefType::ClassAttribute({ + _pyo3::class::PyClassAttributeDef::new( #python_name, - ::pyo3::class::methods::PyClassAttributeFactory({ - fn __wrap(py: ::pyo3::Python<'_>) -> ::pyo3::PyObject { + _pyo3::class::methods::PyClassAttributeFactory({ + fn __wrap(py: _pyo3::Python<'_>) -> _pyo3::PyObject { #deprecations - ::pyo3::IntoPy::into_py(#cls::#member, py) + _pyo3::IntoPy::into_py(#cls::#member, py) } __wrap }) @@ -141,11 +141,11 @@ pub fn gen_py_const(cls: &syn::Type, spec: &ConstSpec) -> TokenStream { fn impl_py_methods(ty: &syn::Type, methods: Vec) -> TokenStream { quote! { - impl ::pyo3::class::impl_::PyMethods<#ty> - for ::pyo3::class::impl_::PyClassImplCollector<#ty> + impl _pyo3::class::impl_::PyMethods<#ty> + for _pyo3::class::impl_::PyClassImplCollector<#ty> { - fn py_methods(self) -> &'static [::pyo3::class::methods::PyMethodDefType] { - static METHODS: &[::pyo3::class::methods::PyMethodDefType] = &[#(#methods),*]; + fn py_methods(self) -> &'static [_pyo3::class::methods::PyMethodDefType] { + static METHODS: &[_pyo3::class::methods::PyMethodDefType] = &[#(#methods),*]; METHODS } } @@ -162,7 +162,7 @@ fn add_shared_proto_slots( let first_implemented = implemented_proto_fragments.remove($first); let second_implemented = implemented_proto_fragments.remove($second); if first_implemented || second_implemented { - proto_impls.push(quote! { ::pyo3::$slot!(#ty) }) + proto_impls.push(quote! { _pyo3::$slot!(#ty) }) } }}; } @@ -194,10 +194,10 @@ fn add_shared_proto_slots( fn impl_protos(ty: &syn::Type, proto_impls: Vec) -> TokenStream { quote! { - impl ::pyo3::class::impl_::PyMethodsProtocolSlots<#ty> - for ::pyo3::class::impl_::PyClassImplCollector<#ty> + impl _pyo3::class::impl_::PyMethodsProtocolSlots<#ty> + for _pyo3::class::impl_::PyClassImplCollector<#ty> { - fn methods_protocol_slots(self) -> &'static [::pyo3::ffi::PyType_Slot] { + fn methods_protocol_slots(self) -> &'static [_pyo3::ffi::PyType_Slot] { &[#(#proto_impls),*] } } @@ -210,8 +210,8 @@ fn submit_methods_inventory( proto_impls: Vec, ) -> TokenStream { quote! { - ::pyo3::inventory::submit! { - type Inventory = <#ty as ::pyo3::class::impl_::PyClassImpl>::Inventory; + _pyo3::inventory::submit! { + type Inventory = <#ty as _pyo3::class::impl_::PyClassImpl>::Inventory; Inventory::new(&[#(#methods),*], &[#(#proto_impls),*]) } } diff --git a/pyo3-macros-backend/src/pymethod.rs b/pyo3-macros-backend/src/pymethod.rs index 1b5951a43e9..c8b4d607e5b 100644 --- a/pyo3-macros-backend/src/pymethod.rs +++ b/pyo3-macros-backend/src/pymethod.rs @@ -120,12 +120,12 @@ pub fn gen_py_method( (_, FnType::FnClass) => GeneratedPyMethod::Method(impl_py_method_def( cls, spec, - Some(quote!(::pyo3::ffi::METH_CLASS)), + Some(quote!(_pyo3::ffi::METH_CLASS)), )?), (_, FnType::FnStatic) => GeneratedPyMethod::Method(impl_py_method_def( cls, spec, - Some(quote!(::pyo3::ffi::METH_STATIC)), + Some(quote!(_pyo3::ffi::METH_STATIC)), )?), // special prototypes (_, FnType::FnNew) => GeneratedPyMethod::TraitImpl(impl_py_method_def_new(cls, spec)?), @@ -186,7 +186,7 @@ pub fn impl_py_method_def( }; let methoddef = spec.get_methoddef(quote! {{ #wrapper_def #wrapper_ident }}); Ok(quote! { - ::pyo3::class::PyMethodDefType::#methoddef_type(#methoddef #add_flags) + _pyo3::class::PyMethodDefType::#methoddef_type(#methoddef #add_flags) }) } @@ -194,8 +194,8 @@ fn impl_py_method_def_new(cls: &syn::Type, spec: &FnSpec) -> Result let wrapper_ident = syn::Ident::new("__wrap", Span::call_site()); let wrapper = spec.get_wrapper_function(&wrapper_ident, Some(cls))?; Ok(quote! { - impl ::pyo3::class::impl_::PyClassNewImpl<#cls> for ::pyo3::class::impl_::PyClassImplCollector<#cls> { - fn new_impl(self) -> ::std::option::Option<::pyo3::ffi::newfunc> { + impl _pyo3::class::impl_::PyClassNewImpl<#cls> for _pyo3::class::impl_::PyClassImplCollector<#cls> { + fn new_impl(self) -> ::std::option::Option<_pyo3::ffi::newfunc> { ::std::option::Option::Some({ #wrapper #wrapper_ident @@ -214,9 +214,9 @@ fn impl_call_slot(cls: &syn::Type, mut spec: FnSpec) -> Result { let wrapper = spec.get_wrapper_function(&wrapper_ident, Some(cls))?; Ok(quote! {{ #wrapper - ::pyo3::ffi::PyType_Slot { - slot: ::pyo3::ffi::Py_tp_call, - pfunc: __wrap as ::pyo3::ffi::ternaryfunc as _ + _pyo3::ffi::PyType_Slot { + slot: _pyo3::ffi::Py_tp_call, + pfunc: __wrap as _pyo3::ffi::ternaryfunc as _ } }}) } @@ -226,13 +226,13 @@ fn impl_py_class_attribute(cls: &syn::Type, spec: &FnSpec) -> TokenStream { let deprecations = &spec.deprecations; let python_name = spec.null_terminated_python_name(); quote! { - ::pyo3::class::PyMethodDefType::ClassAttribute({ - ::pyo3::class::PyClassAttributeDef::new( + _pyo3::class::PyMethodDefType::ClassAttribute({ + _pyo3::class::PyClassAttributeDef::new( #python_name, - ::pyo3::class::methods::PyClassAttributeFactory({ - fn __wrap(py: ::pyo3::Python<'_>) -> ::pyo3::PyObject { + _pyo3::class::methods::PyClassAttributeFactory({ + fn __wrap(py: _pyo3::Python<'_>) -> _pyo3::PyObject { #deprecations - ::pyo3::IntoPy::into_py(#cls::#name(), py) + _pyo3::IntoPy::into_py(#cls::#name(), py) } __wrap }) @@ -295,26 +295,26 @@ pub fn impl_py_setter_def(cls: &syn::Type, property_type: PropertyType) -> Resul } }; Ok(quote! { - ::pyo3::class::PyMethodDefType::Setter({ + _pyo3::class::PyMethodDefType::Setter({ #deprecations - ::pyo3::class::PySetterDef::new( + _pyo3::class::PySetterDef::new( #python_name, - ::pyo3::class::methods::PySetter({ + _pyo3::class::methods::PySetter({ unsafe extern "C" fn __wrap( - _slf: *mut ::pyo3::ffi::PyObject, - _value: *mut ::pyo3::ffi::PyObject, + _slf: *mut _pyo3::ffi::PyObject, + _value: *mut _pyo3::ffi::PyObject, _: *mut ::std::os::raw::c_void ) -> ::std::os::raw::c_int { - ::pyo3::callback::handle_panic(|_py| { + _pyo3::callback::handle_panic(|_py| { #slf let _value = _py .from_borrowed_ptr_or_opt(_value) .ok_or_else(|| { - ::pyo3::exceptions::PyAttributeError::new_err("can't delete attribute") + _pyo3::exceptions::PyAttributeError::new_err("can't delete attribute") })?; - let _val = ::pyo3::FromPyObject::extract(_value)?; + let _val = _pyo3::FromPyObject::extract(_value)?; - ::pyo3::callback::convert(_py, #setter_impl) + _pyo3::callback::convert(_py, #setter_impl) }) } __wrap @@ -375,18 +375,18 @@ pub fn impl_py_getter_def(cls: &syn::Type, property_type: PropertyType) -> Resul } }; Ok(quote! { - ::pyo3::class::PyMethodDefType::Getter({ + _pyo3::class::PyMethodDefType::Getter({ #deprecations - ::pyo3::class::PyGetterDef::new( + _pyo3::class::PyGetterDef::new( #python_name, - ::pyo3::class::methods::PyGetter({ + _pyo3::class::methods::PyGetter({ unsafe extern "C" fn __wrap( - _slf: *mut ::pyo3::ffi::PyObject, + _slf: *mut _pyo3::ffi::PyObject, _: *mut ::std::os::raw::c_void - ) -> *mut ::pyo3::ffi::PyObject { - ::pyo3::callback::handle_panic(|_py| { + ) -> *mut _pyo3::ffi::PyObject { + _pyo3::callback::handle_panic(|_py| { #slf - ::pyo3::callback::convert(_py, #getter_impl) + _pyo3::callback::convert(_py, #getter_impl) }) } __wrap @@ -459,10 +459,10 @@ const __GETATTR__: SlotDef = SlotDef::new("Py_tp_getattro", "getattrofunc") quote! { // Behave like python's __getattr__ (as opposed to __getattribute__) and check // for existing fields and methods first - let existing = ::pyo3::ffi::PyObject_GenericGetAttr(_slf, arg0); + let existing = _pyo3::ffi::PyObject_GenericGetAttr(_slf, arg0); if existing.is_null() { // PyObject_HasAttr also tries to get an object and clears the error if it fails - ::pyo3::ffi::PyErr_Clear(); + _pyo3::ffi::PyErr_Clear(); } else { return existing; } @@ -473,7 +473,7 @@ const __REPR__: SlotDef = SlotDef::new("Py_tp_repr", "reprfunc"); const __HASH__: SlotDef = SlotDef::new("Py_tp_hash", "hashfunc") .ret_ty(Ty::PyHashT) .return_conversion(TokenGenerator( - || quote! { ::pyo3::callback::HashCallbackOutput }, + || quote! { _pyo3::callback::HashCallbackOutput }, )); const __RICHCMP__: SlotDef = SlotDef::new("Py_tp_richcompare", "richcmpfunc") .extract_error_mode(ExtractErrorMode::NotImplemented) @@ -482,12 +482,12 @@ const __GET__: SlotDef = SlotDef::new("Py_tp_descr_get", "descrgetfunc") .arguments(&[Ty::MaybeNullObject, Ty::MaybeNullObject]); const __ITER__: SlotDef = SlotDef::new("Py_tp_iter", "getiterfunc"); const __NEXT__: SlotDef = SlotDef::new("Py_tp_iternext", "iternextfunc").return_conversion( - TokenGenerator(|| quote! { ::pyo3::class::iter::IterNextOutput::<_, _> }), + TokenGenerator(|| quote! { _pyo3::class::iter::IterNextOutput::<_, _> }), ); const __AWAIT__: SlotDef = SlotDef::new("Py_am_await", "unaryfunc"); const __AITER__: SlotDef = SlotDef::new("Py_am_aiter", "unaryfunc"); const __ANEXT__: SlotDef = SlotDef::new("Py_am_anext", "unaryfunc").return_conversion( - TokenGenerator(|| quote! { ::pyo3::class::pyasync::IterANextOutput::<_, _> }), + TokenGenerator(|| quote! { _pyo3::class::pyasync::IterANextOutput::<_, _> }), ); const __LEN__: SlotDef = SlotDef::new("Py_mp_length", "lenfunc").ret_ty(Ty::PySsizeT); const __CONTAINS__: SlotDef = SlotDef::new("Py_sq_contains", "objobjproc") @@ -613,11 +613,11 @@ enum Ty { impl Ty { fn ffi_type(self) -> TokenStream { match self { - Ty::Object | Ty::MaybeNullObject => quote! { *mut ::pyo3::ffi::PyObject }, - Ty::NonNullObject => quote! { ::std::ptr::NonNull<::pyo3::ffi::PyObject> }, + Ty::Object | Ty::MaybeNullObject => quote! { *mut _pyo3::ffi::PyObject }, + Ty::NonNullObject => quote! { ::std::ptr::NonNull<_pyo3::ffi::PyObject> }, Ty::Int | Ty::CompareOp => quote! { ::std::os::raw::c_int }, - Ty::PyHashT => quote! { ::pyo3::ffi::Py_hash_t }, - Ty::PySsizeT => quote! { ::pyo3::ffi::Py_ssize_t }, + Ty::PyHashT => quote! { _pyo3::ffi::Py_hash_t }, + Ty::PySsizeT => quote! { _pyo3::ffi::Py_ssize_t }, Ty::Void => quote! { () }, } } @@ -636,7 +636,7 @@ impl Ty { extract_error_mode, py, quote! { - #py.from_borrowed_ptr::<::pyo3::PyAny>(#ident).extract() + #py.from_borrowed_ptr::<_pyo3::PyAny>(#ident).extract() }, ); extract_object(cls, arg.ty, ident, extract) @@ -646,9 +646,9 @@ impl Ty { extract_error_mode, py, quote! { - #py.from_borrowed_ptr::<::pyo3::PyAny>( + #py.from_borrowed_ptr::<_pyo3::PyAny>( if #ident.is_null() { - ::pyo3::ffi::Py_None() + _pyo3::ffi::Py_None() } else { #ident } @@ -662,7 +662,7 @@ impl Ty { extract_error_mode, py, quote! { - #py.from_borrowed_ptr::<::pyo3::PyAny>(#ident.as_ptr()).extract() + #py.from_borrowed_ptr::<_pyo3::PyAny>(#ident.as_ptr()).extract() }, ); extract_object(cls, arg.ty, ident, extract) @@ -672,8 +672,8 @@ impl Ty { extract_error_mode, py, quote! { - ::pyo3::class::basic::CompareOp::from_raw(#ident) - .ok_or_else(|| ::pyo3::exceptions::PyValueError::new_err("invalid comparison operator")) + _pyo3::class::basic::CompareOp::from_raw(#ident) + .ok_or_else(|| _pyo3::exceptions::PyValueError::new_err("invalid comparison operator")) }, ); quote! { @@ -695,7 +695,7 @@ fn handle_error( ExtractErrorMode::NotImplemented => quote! { match #extract { ::std::result::Result::Ok(value) => value, - ::std::result::Result::Err(_) => { return ::pyo3::callback::convert(#py, #py.NotImplemented()); }, + ::std::result::Result::Err(_) => { return _pyo3::callback::convert(#py, #py.NotImplemented()); }, } }, } @@ -712,7 +712,7 @@ fn extract_object( replace_self(&mut tref.elem, cls); let mut_ = tref.mutability; quote! { - let #mut_ #ident: <#tref as ::pyo3::derive_utils::ExtractExt<'_>>::Target = #extract; + let #mut_ #ident: <#tref as _pyo3::derive_utils::ExtractExt<'_>>::Target = #extract; let #ident = &#mut_ *#ident; } } else { @@ -731,13 +731,13 @@ impl ReturnMode { fn return_call_output(&self, py: &syn::Ident, call: TokenStream) -> TokenStream { match self { ReturnMode::Conversion(conversion) => quote! { - let _result: ::pyo3::PyResult<#conversion> = #call; - ::pyo3::callback::convert(#py, _result) + let _result: _pyo3::PyResult<#conversion> = #call; + _pyo3::callback::convert(#py, _result) }, ReturnMode::ReturnSelf => quote! { - let _result: ::pyo3::PyResult<()> = #call; + let _result: _pyo3::PyResult<()> = #call; _result?; - ::pyo3::ffi::Py_XINCREF(_raw_slf); + _pyo3::ffi::Py_XINCREF(_raw_slf); ::std::result::Result::Ok(_raw_slf) }, } @@ -821,16 +821,16 @@ impl SlotDef { return_mode.as_ref(), )?; Ok(quote!({ - unsafe extern "C" fn __wrap(_raw_slf: *mut ::pyo3::ffi::PyObject, #(#method_arguments),*) -> #ret_ty { + unsafe extern "C" fn __wrap(_raw_slf: *mut _pyo3::ffi::PyObject, #(#method_arguments),*) -> #ret_ty { let _slf = _raw_slf; #before_call_method - ::pyo3::callback::handle_panic(|#py| { + _pyo3::callback::handle_panic(|#py| { #body }) } - ::pyo3::ffi::PyType_Slot { - slot: ::pyo3::ffi::#slot, - pfunc: __wrap as ::pyo3::ffi::#func_ty as _ + _pyo3::ffi::PyType_Slot { + slot: _pyo3::ffi::#slot, + pfunc: __wrap as _pyo3::ffi::#func_ty as _ } })) } @@ -858,7 +858,7 @@ fn generate_method_body( let rust_name = spec.name; let (arg_idents, conversions) = extract_proto_arguments(cls, py, &spec.args, arguments, extract_error_mode)?; - let call = quote! { ::pyo3::callback::convert(#py, #cls::#rust_name(_slf, #(#arg_idents),*)) }; + let call = quote! { _pyo3::callback::convert(#py, #cls::#rust_name(_slf, #(#arg_idents),*)) }; let body = if let Some(return_mode) = return_mode { return_mode.return_call_output(py, call) } else { @@ -912,15 +912,15 @@ impl SlotFragmentDef { let body = generate_method_body(cls, spec, &py, arguments, *extract_error_mode, None)?; let ret_ty = ret_ty.ffi_type(); Ok(quote! { - impl ::pyo3::class::impl_::#fragment_trait<#cls> for ::pyo3::class::impl_::PyClassImplCollector<#cls> { + impl _pyo3::class::impl_::#fragment_trait<#cls> for _pyo3::class::impl_::PyClassImplCollector<#cls> { #[inline] unsafe fn #method( self, - #py: ::pyo3::Python, - _raw_slf: *mut ::pyo3::ffi::PyObject, + #py: _pyo3::Python, + _raw_slf: *mut _pyo3::ffi::PyObject, #(#method_arguments),* - ) -> ::pyo3::PyResult<#ret_ty> { + ) -> _pyo3::PyResult<#ret_ty> { let _slf = _raw_slf; #body } diff --git a/pyo3-macros-backend/src/pyproto.rs b/pyo3-macros-backend/src/pyproto.rs index 779cce253e0..eda675bfce9 100644 --- a/pyo3-macros-backend/src/pyproto.rs +++ b/pyo3-macros-backend/src/pyproto.rs @@ -67,7 +67,7 @@ fn impl_proto_impl( let flags = if m.can_coexist { // We need METH_COEXIST here to prevent __add__ from overriding __radd__ - Some(quote!(::pyo3::ffi::METH_COEXIST)) + Some(quote!(_pyo3::ffi::METH_COEXIST)) } else { None }; @@ -105,11 +105,11 @@ fn impl_normal_methods( let methods_trait = proto.methods_trait(); let methods_trait_methods = proto.methods_trait_methods(); quote! { - impl ::pyo3::class::impl_::#methods_trait<#ty> - for ::pyo3::class::impl_::PyClassImplCollector<#ty> + impl _pyo3::class::impl_::#methods_trait<#ty> + for _pyo3::class::impl_::PyClassImplCollector<#ty> { - fn #methods_trait_methods(self) -> &'static [::pyo3::class::methods::PyMethodDefType] { - static METHODS: &[::pyo3::class::methods::PyMethodDefType] = + fn #methods_trait_methods(self) -> &'static [_pyo3::class::methods::PyMethodDefType] { + static METHODS: &[_pyo3::class::methods::PyMethodDefType] = &[#(#py_methods),*]; METHODS } @@ -138,16 +138,16 @@ fn impl_proto_methods( if build_config.version <= PY39 && proto.name == "Buffer" { maybe_buffer_methods = Some(quote! { - impl ::pyo3::class::impl_::PyBufferProtocolProcs<#ty> - for ::pyo3::class::impl_::PyClassImplCollector<#ty> + impl _pyo3::class::impl_::PyBufferProtocolProcs<#ty> + for _pyo3::class::impl_::PyClassImplCollector<#ty> { fn buffer_procs( self - ) -> ::std::option::Option<&'static ::pyo3::class::impl_::PyBufferProcs> { - static PROCS: ::pyo3::class::impl_::PyBufferProcs - = ::pyo3::class::impl_::PyBufferProcs { - bf_getbuffer: ::std::option::Option::Some(::pyo3::class::buffer::getbuffer::<#ty>), - bf_releasebuffer: ::std::option::Option::Some(::pyo3::class::buffer::releasebuffer::<#ty>), + ) -> ::std::option::Option<&'static _pyo3::class::impl_::PyBufferProcs> { + static PROCS: _pyo3::class::impl_::PyBufferProcs + = _pyo3::class::impl_::PyBufferProcs { + bf_getbuffer: ::std::option::Option::Some(_pyo3::class::buffer::getbuffer::<#ty>), + bf_releasebuffer: ::std::option::Option::Some(_pyo3::class::buffer::releasebuffer::<#ty>), }; ::std::option::Option::Some(&PROCS) } @@ -161,8 +161,8 @@ fn impl_proto_methods( let slot = syn::Ident::new(def.slot, Span::call_site()); let slot_impl = syn::Ident::new(def.slot_impl, Span::call_site()); quote! {{ - ::pyo3::ffi::PyType_Slot { - slot: ::pyo3::ffi::#slot, + _pyo3::ffi::PyType_Slot { + slot: _pyo3::ffi::#slot, pfunc: #module::#slot_impl::<#ty> as _ } }} @@ -176,10 +176,10 @@ fn impl_proto_methods( quote! { #maybe_buffer_methods - impl ::pyo3::class::impl_::#slots_trait<#ty> - for ::pyo3::class::impl_::PyClassImplCollector<#ty> + impl _pyo3::class::impl_::#slots_trait<#ty> + for _pyo3::class::impl_::PyClassImplCollector<#ty> { - fn #slots_trait_slots(self) -> &'static [::pyo3::ffi::PyType_Slot] { + fn #slots_trait_slots(self) -> &'static [_pyo3::ffi::PyType_Slot] { &[#(#tokens),*] } }