paultiq commented on issue #47823:
URL: https://github.com/apache/arrow/issues/47823#issuecomment-3478062807

   Would you consider an #if block specific for 3.15+ like the following, 
leaving <=3.14 alone. 
   
   \* This built/ran/passed tests on my local system.
   
   Other approaches: 
   - 
[c-api-pending-removal-in-3.15](https://docs.python.org/3/deprecations/c-api-pending-removal-in-3.15.html)
 suggests we could use: 
[pythoncapi-compat](https://github.com/python/pythoncapi-compat/), but that 
seems like unnecessary complexity. 
   - Cython added a backport: 
https://github.com/cython/cython/blob/master/Cython/Includes/cpython/weakref.pxd.
 This has one difference in PyWeakref_GET_OBJECT: it checks for `inst == NULL`
   ```diff
   diff --git a/python/pyarrow/src/arrow/python/extension_type.cc 
b/python/pyarrow/src/arrow/python/extension_type.cc
   index 8439ecf858..a2110f9799 100644
   --- a/python/pyarrow/src/arrow/python/extension_type.cc
   +++ b/python/pyarrow/src/arrow/python/extension_type.cc
   @@ -164,6 +164,22 @@ PyObject* PyExtensionType::GetInstance() const {
        return nullptr;
      }
      ARROW_DCHECK(PyWeakref_CheckRef(type_instance_.obj()));
   +#if PY_VERSION_HEX >= 0x030F0000  // Python 3.15+
   +  PyObject* inst = NULL;
   +  int result = PyWeakref_GetRef(type_instance_.obj(), &inst);
   +  if (result < 0) {
   +    // Error
   +    return nullptr;
   +  } else if (result == 0) {
   +    // Reconstruct - XXX cache again? 
   +    return DeserializeExtInstance(type_class_.obj(), storage_type_, 
serialized_);
   +  } else {
   +    // Cached instance still alive
   +    return inst;
   +  }
   +#else
   +  // PyWeakref_GET_OBJECT removed in 3.15
      PyObject* inst = PyWeakref_GET_OBJECT(type_instance_.obj());
      if (inst != Py_None) {
        // Cached instance still alive
        Py_INCREF(inst);
        return inst;
      } else {
        // Must reconstruct from serialized form
        // XXX cache again?
        return DeserializeExtInstance(type_class_.obj(), storage_type_, 
serialized_);
      }
   +#endif
    }
   ```


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