Skip to content

Commit dbcd614

Browse files
fix macro namespacing
1 parent 205d1b9 commit dbcd614

2 files changed

Lines changed: 35 additions & 29 deletions

File tree

newsfragments/6228.fixed.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Fix reversible arithmetic operators don't respect subclassing if only one arm implemented Closes #6024
1+
Fix reversible arithmetic operators don't respect subclassing if only one arm implemented

src/impl_/pyclass.rs

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ macro_rules! define_pyclass_binary_operator_slot {
571571
_other: *mut $crate::ffi::PyObject,
572572
) -> $crate::PyResult<*mut $crate::ffi::PyObject> {
573573
use $crate::impl_::pyclass::*;
574+
use $crate::types::PyAnyMethods;
574575
let collector = PyClassImplCollector::<$cls>::new();
575576

576577
let lhs_obj = unsafe { $crate::Bound::from_borrowed_ptr(py, _slf) };
@@ -583,7 +584,7 @@ macro_rules! define_pyclass_binary_operator_slot {
583584
return unsafe { collector.$rhs(py, _other, _slf) };
584585
}
585586

586-
Result::Ok(py.NotImplemented().into_ptr())
587+
::core::result::Result::Ok(py.NotImplemented().into_ptr())
587588
}
588589

589590
$crate::ffi::PyType_Slot {
@@ -602,6 +603,7 @@ macro_rules! define_pyclass_binary_operator_slot {
602603
_other: *mut $crate::ffi::PyObject,
603604
) -> $crate::PyResult<*mut $crate::ffi::PyObject> {
604605
use $crate::impl_::pyclass::*;
606+
use $crate::types::PyAnyMethods;
605607
let lhs_obj = unsafe { $crate::Bound::from_borrowed_ptr(py, _slf) };
606608

607609
if lhs_obj.is_instance_of::<$cls>() {
@@ -616,22 +618,22 @@ macro_rules! define_pyclass_binary_operator_slot {
616618
let py_type = <$cls as $crate::PyTypeInfo>::type_object(py);
617619
let reflected_name = $crate::intern!(py, concat!(stringify!($rhs)));
618620
let super_obj = match $crate::types::PySuper::new(&py_type, &rhs_obj) {
619-
Ok(s) => s,
620-
Err(e) => return Err(e),
621+
::core::result::Result::Ok(s) => s,
622+
::core::result::Result::Err(e) => return ::core::result::Result::Err(e),
621623
};
622624
match super_obj.call_method1(reflected_name, (&lhs_obj,)) {
623-
Ok(result) => return Ok(result.into_ptr()),
624-
Err(e) => {
625+
::core::result::Result::Ok(result) => return ::core::result::Result::Ok(result.into_ptr()),
626+
::core::result::Result::Err(e) => {
625627
// If parent doesn't implement the method, return NotImplemented instead of AttributeError
626628
if e.is_instance_of::<$crate::exceptions::PyAttributeError>(py) {
627-
return Ok(py.NotImplemented().into_ptr());
629+
return ::core::result::Result::Ok(py.NotImplemented().into_ptr());
628630
} else {
629-
return Err(e);
631+
return ::core::result::Result::Err(e);
630632
}
631633
}
632634
}
633635
}
634-
Result::Ok(py.NotImplemented().into_ptr())
636+
::core::result::Result::Ok(py.NotImplemented().into_ptr())
635637
}
636638

637639
$crate::ffi::PyType_Slot {
@@ -650,6 +652,7 @@ macro_rules! define_pyclass_binary_operator_slot {
650652
_other: *mut $crate::ffi::PyObject,
651653
) -> $crate::PyResult<*mut $crate::ffi::PyObject> {
652654
use $crate::impl_::pyclass::*;
655+
use $crate::types::PyAnyMethods;
653656

654657
let lhs_obj = unsafe { $crate::Bound::from_borrowed_ptr(py, _slf) };
655658
if lhs_obj.is_instance_of::<$cls>() {
@@ -659,17 +662,17 @@ macro_rules! define_pyclass_binary_operator_slot {
659662
let forward_name = $crate::intern!(py, concat!(stringify!($lhs)));
660663
let other_bound = unsafe { $crate::Bound::from_borrowed_ptr(py, _other) };
661664
let super_obj = match $crate::types::PySuper::new(&py_type, &lhs_obj) {
662-
Ok(s) => s,
663-
Err(e) => return Err(e),
665+
::core::result::Result::Ok(s) => s,
666+
::core::result::Result::Err(e) => return ::core::result::Result::Err(e),
664667
};
665668
match super_obj.call_method1(forward_name, (&other_bound,)) {
666-
Ok(result) => return Ok(result.into_ptr()),
667-
Err(e) => {
669+
::core::result::Result::Ok(result) => return ::core::result::Result::Ok(result.into_ptr()),
670+
::core::result::Result::Err(e) => {
668671
// If parent doesn't implement the method, return NotImplemented instead of AttributeError
669672
if e.is_instance_of::<$crate::exceptions::PyAttributeError>(py) {
670-
return Ok(py.NotImplemented().into_ptr());
673+
return ::core::result::Result::Ok(py.NotImplemented().into_ptr());
671674
} else {
672-
return Err(e);
675+
return ::core::result::Result::Err(e);
673676
}
674677
}
675678
}
@@ -682,7 +685,7 @@ macro_rules! define_pyclass_binary_operator_slot {
682685
return unsafe { collector.$rhs(py, _other, _slf) };
683686
}
684687

685-
Result::Ok(py.NotImplemented().into_ptr())
688+
::core::result::Result::Ok(py.NotImplemented().into_ptr())
686689
}
687690

688691
$crate::ffi::PyType_Slot {
@@ -858,6 +861,7 @@ macro_rules! generate_pyclass_pow_slot {
858861
_mod: *mut $crate::ffi::PyObject,
859862
) -> $crate::PyResult<*mut $crate::ffi::PyObject> {
860863
use $crate::impl_::pyclass::*;
864+
use $crate::types::PyAnyMethods;
861865
let collector = PyClassImplCollector::<$cls>::new();
862866

863867
let lhs_obj = unsafe { $crate::Bound::from_borrowed_ptr(py, _slf) };
@@ -870,7 +874,7 @@ macro_rules! generate_pyclass_pow_slot {
870874
return unsafe { collector.__rpow__(py, _other, _slf, _mod) };
871875
}
872876

873-
Result::Ok(py.NotImplemented().into_ptr())
877+
::core::result::Result::Ok(py.NotImplemented().into_ptr())
874878
}
875879

876880
$crate::ffi::PyType_Slot {
@@ -889,6 +893,7 @@ macro_rules! generate_pyclass_pow_slot {
889893
_mod: *mut $crate::ffi::PyObject,
890894
) -> $crate::PyResult<*mut $crate::ffi::PyObject> {
891895
use $crate::impl_::pyclass::*;
896+
use $crate::types::PyAnyMethods;
892897
let lhs_obj = unsafe { $crate::Bound::from_borrowed_ptr(py, _slf) };
893898

894899
if lhs_obj.is_instance_of::<$cls>() {
@@ -907,22 +912,22 @@ macro_rules! generate_pyclass_pow_slot {
907912
unsafe { $crate::Bound::from_borrowed_ptr(py, _mod) }
908913
};
909914
let super_obj = match $crate::types::PySuper::new(&py_type, &rhs_obj) {
910-
Ok(s) => s,
911-
Err(e) => return Err(e),
915+
::core::result::Result::Ok(s) => s,
916+
::core::result::Result::Err(e) => return ::core::result::Result::Err(e),
912917
};
913918
match super_obj.call_method1($crate::intern!(py, "__rpow__"), (&lhs_obj, mod_obj)) {
914-
Ok(result) => return Ok(result.into_ptr()),
915-
Err(e) => {
919+
::core::result::Result::Ok(result) => return ::core::result::Result::Ok(result.into_ptr()),
920+
::core::result::Result::Err(e) => {
916921
// If parent doesn't implement the method, return NotImplemented instead of AttributeError
917922
if e.is_instance_of::<$crate::exceptions::PyAttributeError>(py) {
918-
return Ok(py.NotImplemented().into_ptr());
923+
return ::core::result::Result::Ok(py.NotImplemented().into_ptr());
919924
} else {
920-
return Err(e);
925+
return ::core::result::Result::Err(e);
921926
}
922927
}
923928
}
924929
}
925-
Result::Ok(py.NotImplemented().into_ptr())
930+
::core::result::Result::Ok(py.NotImplemented().into_ptr())
926931
}
927932

928933
$crate::ffi::PyType_Slot {
@@ -941,6 +946,7 @@ macro_rules! generate_pyclass_pow_slot {
941946
_mod: *mut $crate::ffi::PyObject,
942947
) -> $crate::PyResult<*mut $crate::ffi::PyObject> {
943948
use $crate::impl_::pyclass::*;
949+
use $crate::types::PyAnyMethods;
944950

945951
let lhs_obj = unsafe { $crate::Bound::from_borrowed_ptr(py, _slf) };
946952
if lhs_obj.is_instance_of::<$cls>() {
@@ -958,13 +964,13 @@ macro_rules! generate_pyclass_pow_slot {
958964
Err(e) => return Err(e),
959965
};
960966
match super_obj.call_method1($crate::intern!(py, "__pow__"), (&rhs_obj, mod_obj)) {
961-
Ok(result) => return Ok(result.into_ptr()),
962-
Err(e) => {
967+
::core::result::Result::Ok(result) => return ::core::result::Result::Ok(result.into_ptr()),
968+
::core::result::Result::Err(e) => {
963969
// If parent doesn't implement the method, return NotImplemented instead of AttributeError
964970
if e.is_instance_of::<$crate::exceptions::PyAttributeError>(py) {
965-
return Ok(py.NotImplemented().into_ptr());
971+
return ::core::result::Result::Ok(py.NotImplemented().into_ptr());
966972
} else {
967-
return Err(e);
973+
return ::core::result::Result::Err(e);
968974
}
969975
}
970976
}
@@ -977,7 +983,7 @@ macro_rules! generate_pyclass_pow_slot {
977983
return unsafe { collector.__rpow__(py, _other, _slf, _mod) };
978984
}
979985

980-
Result::Ok(py.NotImplemented().into_ptr())
986+
::core::result::Result::Ok(py.NotImplemented().into_ptr())
981987
}
982988

983989
$crate::ffi::PyType_Slot {

0 commit comments

Comments
 (0)