timsaucer commented on code in PR #9660:
URL: https://github.com/apache/arrow-rs/pull/9660#discussion_r3428094614


##########
arrow-pyarrow/src/lib.rs:
##########
@@ -628,3 +544,78 @@ impl<T> From<T> for PyArrowType<T> {
         Self(s)
     }
 }
+
+fn call_capsule_method_if_exists<'py>(
+    object: &Bound<'py, PyAny>,
+    method_name: &'static str,
+) -> PyResult<Option<Bound<'py, PyCapsule>>> {
+    let Some(method) = object.getattr_opt(method_name)? else {
+        return Ok(None);
+    };
+    Ok(Some(method.call0()?.extract().map_err(
+        |e: CastError| {
+            wrapping_type_error(
+                object.py(),
+                e.into(),
+                format!("Expected {method_name} to return a capsule."),
+            )
+        },
+    )?))
+}
+
+fn call_capsule_pair_method_if_exists<'py>(
+    object: &Bound<'py, PyAny>,
+    method_name: &'static str,
+) -> PyResult<Option<(Bound<'py, PyCapsule>, Bound<'py, PyCapsule>)>> {
+    let Some(method) = object.getattr_opt(method_name)? else {
+        return Ok(None);
+    };
+    Ok(Some(method.call0()?.extract().map_err(|e| {
+        wrapping_type_error(
+            object.py(),
+            e,
+            format!("Expected {method_name} to return a pair of capsules."),
+        )
+    })?))
+}
+
+trait PyCapsuleType {
+    const NAME: &CStr;
+}
+
+impl PyCapsuleType for FFI_ArrowSchema {
+    const NAME: &CStr = c"arrow_schema";
+}
+
+impl PyCapsuleType for FFI_ArrowArray {
+    const NAME: &CStr = c"arrow_array";
+}
+
+impl PyCapsuleType for FFI_ArrowArrayStream {
+    const NAME: &CStr = c"arrow_array_stream";
+}

Review Comment:
   This seems like overkill. Why not just keep these as constants like we had 
before and pass them as needed?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to