summaryrefslogtreecommitdiff
path: root/numpy/core/_internal.py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2018-06-08 13:31:53 -0600
committerGitHub <noreply@github.com>2018-06-08 13:31:53 -0600
commit71650e304a0be2851b76a2465b7eef65210db53d (patch)
treef4f57315988c7eb7e2a7279de2beaf0d4a9ef9f0 /numpy/core/_internal.py
parentaf66e487a57bfd4850f4306e3b85d1dac3c70412 (diff)
parent1e5df66c4ca420fc1afd736120e6d01449a4ba8f (diff)
downloadnumpy-71650e304a0be2851b76a2465b7eef65210db53d.tar.gz
Merge pull request #11277 from eric-wieser/fix-older-ctypes-compat
BUG: Work around past and present PEP3118 issues in ctypes
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