[docs] [issue37187] CField.size from the ctypes module does not behave as documented on bitfields

Eric Wieser report at bugs.python.org
Thu Jun 6 23:46:36 EDT 2019


New submission from Eric Wieser <wieser.eric at gmail.com>:

This behavior is pretty surprising:

```python
import ctypes

class Simple(ctypes.Structure):
    _fields_ = [
        ('a', ctypes.c_uint8),
        ('b', ctypes.c_uint8),
    ]

class Bitfields(ctypes.Structure):
    _fields_ = [
        ('a', ctypes.c_uint8, 8),
        ('b', ctypes.c_uint8, 8),
    ]

print(Simple.b.size)     # 1
print(Bitfields.b.size)  # 262148
```

The docstring for this field, from `help(type(Bitfields.b).size)`, is:

> Help on getset descriptor _ctypes.CField.size:
>
> size
>    size in bytes of this field

So either the behavior or the docstring needs to change.

----------
assignee: docs at python
components: Documentation
messages: 344895
nosy: Eric Wieser, docs at python
priority: normal
severity: normal
status: open
title: CField.size from the ctypes module does not behave as documented on bitfields

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


More information about the docs mailing list