[New-bugs-announce] [issue45285] c_char incorrectly treated as bytes in Structure

CireSnave report at bugs.python.org
Fri Sep 24 15:23:45 EDT 2021

New submission from CireSnave <ciresnave at yahoo.com>:

When dealing with a Structure containing c_char variables, the variables are incorrectly being typed as bytes.  As a result, a pointer to those c_char variables can not be created because bytes is not a ctypes type.

from ctypes import (

class MyStruct(Structure):
    _fields_ = [("a", c_char), ("b", c_char), ("c", c_char)]

x: MyStruct = MyStruct(98, 99, 100)

# Prints <class 'bytes'> ???  Both mypy and PyRight agree that x.a is a c_char.

some_variable = pointer(x.a)
# Traceback (most recent call last):
#   File "C:\Users\cires\ctypes_test.py", line 23, in <module>
#     some_variable = pointer(x.a)
# TypeError: _type_ must have storage info

components: ctypes
messages: 402582
nosy: ciresnave
priority: normal
severity: normal
status: open
title: c_char incorrectly treated as bytes in Structure
type: behavior
versions: Python 3.9

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list