Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions plugins/python/python/phlex/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,23 @@
}

# ctypes types that don't map cleanly to intN_t / uintN_t
_CTYPES_SPECIAL: dict[type, str] = {
ctypes.c_bool: "bool",
ctypes.c_char: "char", # signedness is implementation-defined in C
ctypes.c_wchar: "wchar_t",
ctypes.c_float: "float", # always IEEE 754 32-bit
ctypes.c_double: "double", # always IEEE 754 64-bit
ctypes.c_longdouble: "long double", # platform-dependent width, no stdint.h alias
# the following types are aliased in ctypes, so ignore here
# ctypes.c_size_t: "size_t",
# ctypes.c_ssize_t: "ssize_t",
ctypes.c_void_p: "void*",
ctypes.c_char_p: "const char*",
ctypes.c_wchar_p: "const wchar_t*",
}
_CTYPES_SPECIAL: dict[type, str] = {}
for _attr, _cpp in [
("c_bool", "bool"),
("c_char", "char"), # signedness is implementation-defined in C
("c_wchar", "wchar_t"),
("c_float", "float"), # always IEEE 754 32-bit
("c_double", "double"), # always IEEE 754 64-bit
("c_longdouble", "long double"), # platform-dependent width, no stdint.h alias
("c_size_t", "size_t"),
("c_ssize_t", "ssize_t"),
("c_void_p", "void*"),
("c_char_p", "const char*"),
("c_wchar_p", "const wchar_t*"),
]:
_tp = getattr(ctypes, _attr)
if _tp.__name__ == _attr: # skip if this ctypes name is just an alias
_CTYPES_SPECIAL[_tp] = _cpp

_CTYPES_INTEGER: list[type] = [
ctypes.c_byte,
Expand Down
2 changes: 1 addition & 1 deletion test/python/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


class TestTYPING:
"""Tests for phlex-specific typinh."""
"""Tests for phlex-specific typing."""

def test_list_normalization(self):
"""Normalization of various forms of list annotations."""
Expand Down
Loading