[New-bugs-announce] [issue43208] Ctypes._FuncPtr.restype doesn't handle NoneType correctly

Thijs Miedema report at bugs.python.org
Fri Feb 12 09:44:57 EST 2021


New submission from Thijs Miedema <thijsmiedema94 at gmail.com>:

When setting the restype of a ctypes._FuncPtr you can use None to indicate a void function. However, I use inspect.signature to dynamically bind python functions to a DLL, and that doesn't return None but NoneType if the type hint return type is None starting at python 3.10.

This change caused me to set the restype to NoneType, which makes ctypes cause a cryptic "TypeError: NoneType takes no arguments" upon returning from a successfully executed C function. 

The included example demonstrates the differing results from inspect, a working example, a failing example and an example that works in 3.9 but fails in 3.10.

Proposed solution: Treat NoneType as None for ctypes._FuncPtr.restype

----------
components: ctypes
files: minimal_example_ctypes_nonetype_behaviour.py
messages: 386867
nosy: thijsmiedema94
priority: normal
severity: normal
status: open
title: Ctypes._FuncPtr.restype doesn't handle NoneType correctly
type: behavior
versions: Python 3.10
Added file: https://bugs.python.org/file49803/minimal_example_ctypes_nonetype_behaviour.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43208>
_______________________________________


More information about the New-bugs-announce mailing list