wjones127 commented on code in PR #39380:
URL: https://github.com/apache/arrow/pull/39380#discussion_r1448245024


##########
python/pyarrow/src/arrow/python/common.cc:
##########
@@ -131,6 +138,34 @@ class PythonErrorDetail : public StatusDetail {
   }
 
  protected:
+  Result<std::string> FormatImpl() const {
+    PyAcquireGIL lock;
+
+    // Use traceback.format_exception()
+    OwnedRef traceback_module;
+    RETURN_NOT_OK(internal::ImportModule("traceback", &traceback_module));
+
+    OwnedRef fmt_exception;
+    RETURN_NOT_OK(internal::ImportFromModule(traceback_module.obj(), 
"format_exception",
+                                             &fmt_exception));
+
+    OwnedRef formatted;
+    formatted.reset(PyObject_CallFunctionObjArgs(fmt_exception.obj(), 
exc_type_.obj(),
+                                                 exc_value_.obj(), 
exc_traceback_.obj(),
+                                                 NULL));
+
+    std::stringstream ss;
+    ss << "Python exception: ";
+    Py_ssize_t num_lines = PyList_GET_SIZE(formatted.obj());

Review Comment:
   The [API 
docs](https://docs.python.org/3/library/traceback.html#traceback.format_exception)
 claim this should return a list, but it's perhaps possible that they might 
change to some other sequence. I changed to be generic sequences.
   
   I assume the function calls will do the type checking internally, correct?



-- 
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