MCPcopy Index your code
hub / github.com/ZeroIntensity/pointers.py / get_mapped

Function get_mapped

src/pointers/_utils.py:91–118  ·  view source on GitHub ↗

Get the C mapped value of the given type.

(typ: Any)

Source from the content-addressed store, hash-verified

89 return ctypes.py_object(data)
90
91def get_mapped(typ: Any) -> "Type[ctypes._CData]":
92 """Get the C mapped value of the given type."""
93 from .c_pointer import VoidPointer
94
95 if getattr(typ, "__origin__", None) is Callable:
96 args = list(typ.__args__)
97 res = args.pop(-1)
98 return ctypes.CFUNCTYPE(get_mapped(res), *map(get_mapped, args))
99
100 if type(typ) in {FunctionType, MethodType}:
101 hints = typ.__annotations__.copy()
102 try:
103 res = hints.pop("return")
104 except KeyError as e:
105 raise TypeError(
106 "return type annotation is required to convert to a C function" # noqa
107 ) from e
108
109 args = hints.values()
110 return ctypes.CFUNCTYPE(
111 get_mapped(res) if res else None,
112 *map(get_mapped, args),
113 )
114
115 # VoidPointer needs to be passed here to stop circular imports
116 return {**_C_TYPES, VoidPointer: ctypes.c_void_p}.get( # type: ignore
117 typ,
118 ) or ctypes.py_object
119
120
121def is_mappable(typ: Any) -> bool:

Callers 10

__init__Method · 0.85
_as_parameter_Method · 0.85
dereferenceMethod · 0.85
_as_parameter_Method · 0.85
arrayFunction · 0.85
_convert_tc_ptrMethod · 0.85
_InternalStructClass · 0.85
sizeofFunction · 0.85
map_typeFunction · 0.85
is_mappableFunction · 0.85

Calls 4

popMethod · 0.80
copyMethod · 0.80
valuesMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected