summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBas van Beek <b.f.van.beek@vu.nl>2021-05-25 20:07:53 +0200
committerBas van Beek <b.f.van.beek@vu.nl>2021-05-25 21:19:59 +0200
commitf5a5fdb345d3d9be90b2bc6832dc6bd0fe66aa5d (patch)
tree14f5f37d83e4133ed4d25e5cfc66f3036db0f641
parent0f10cd9423b589d8b3e5dd814dbe5dfb55f7157e (diff)
downloadnumpy-f5a5fdb345d3d9be90b2bc6832dc6bd0fe66aa5d.tar.gz
MAINT: Refactor the `c_intp`-type inferring function
Model it after `np.core._internal._getintp_ctype` Co-Authored-By: Eric Wieser <425260+eric-wieser@users.noreply.github.com>
-rw-r--r--numpy/typing/mypy_plugin.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/numpy/typing/mypy_plugin.py b/numpy/typing/mypy_plugin.py
index 2a5e729f3..db2dc9b2d 100644
--- a/numpy/typing/mypy_plugin.py
+++ b/numpy/typing/mypy_plugin.py
@@ -62,10 +62,16 @@ def _get_extended_precision_list() -> t.List[str]:
def _get_c_intp_name() -> str:
- if np.ctypeslib.c_intp is np.intp:
- return "c_int64" # Plan B, in case `ctypes` fails to import
+ # Adapted from `np.core._internal._getintp_ctype`
+ char = np.dtype('p').char
+ if char == 'i':
+ return "c_int"
+ elif char == 'l':
+ return "c_long"
+ elif char == 'q':
+ return "c_longlong"
else:
- return np.ctypeslib.c_intp.__qualname__
+ return "c_long"
#: A dictionary mapping type-aliases in `numpy.typing._nbit` to