diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2018-06-08 11:26:28 -0700 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2018-06-08 11:26:28 -0700 |
commit | 1e5df66c4ca420fc1afd736120e6d01449a4ba8f (patch) | |
tree | 3ae4b242cb000665c11876a1179121e3677c68b7 /numpy/core/_internal.py | |
parent | 6a4ca1e78108821989835298bba2323c011e05dd (diff) | |
download | numpy-1e5df66c4ca420fc1afd736120e6d01449a4ba8f.tar.gz |
BUG: Work around bugs in pep3118 ctypes by falling back on np.dtype(type(ctype_obj))
Fixes gh-10528
Fixes gh-10978
Fixes gh-11150
A warning is thrown when ctypes misbehaves, in order to not hide issues that need fixing upstream
Diffstat (limited to 'numpy/core/_internal.py')
-rw-r--r-- | numpy/core/_internal.py | 13 |
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 |