summaryrefslogtreecommitdiff
path: root/numpy/core/_internal.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/core/_internal.py')
-rw-r--r--numpy/core/_internal.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/numpy/core/_internal.py b/numpy/core/_internal.py
index 8c6596d13..9990bacf0 100644
--- a/numpy/core/_internal.py
+++ b/numpy/core/_internal.py
@@ -756,3 +756,16 @@ def _ufunc_doc_signature_formatter(ufunc):
out_args=out_args,
kwargs=kwargs
)
+
+
+def _is_from_ctypes(obj):
+ # determine if an object comes from ctypes, in order to work around
+ # a bug in the buffer protocol for those objects, bpo-10746
+ try:
+ # ctypes class are new-style, so have an __mro__. This probably fails
+ # for ctypes classes with multiple inheritance.
+ ctype_base = type(obj).__mro__[-2]
+ # right now, they're part of the _ctypes module
+ return 'ctypes' in ctype_base.__module__
+ except Exception:
+ return False