Skip to content

Annotation-based decorator for ctypes function pointers #153903

Description

@ZeroIntensity

Feature or enhancement

Proposal:

The idea is to add a decorator that extracts type annotations and a name for a function signature, and then use that information to generate argtypes and restype for a _CFuncPtr object. For example:

@wrap_dll_function(ctypes.pythonapi)
def PyObject_GetAttrString(op: ctypes.py_object, attr: ctypes.c_char_p) -> ctypes.py_object:
    ...

See #104533 for prior work.

Has this already been discussed elsewhere?

I have already discussed this feature proposal on Discourse

Links to previous discussion of this feature:

https://discuss.python.org/t/annotation-based-sugar-for-ctypes/26579

Linked PRs

Metadata

Metadata

Assignees

Labels

sprintstdlibStandard Library Python modules in the Lib/ directorytopic-ctypestype-featureA feature request or enhancement

Fields

No fields configured for issues without a type.

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions