Skip to content

Commit

Permalink
MAINT: Refactor the c_intp-type inferring function
Browse files Browse the repository at this point in the history
Model it after `np.core._internal._getintp_ctype`

Co-Authored-By: Eric Wieser <425260+eric-wieser@users.noreply.github.com>
  • Loading branch information
Bas van Beek and eric-wieser committed May 25, 2021
1 parent 0f10cd9 commit f5a5fdb
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions numpy/typing/mypy_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f5a5fdb

Please sign in to comment.