[issue2680] gotcha: _fields_ is final but accepts lists

Thomas Heller report at bugs.python.org
Thu Apr 24 19:54:08 CEST 2008


Thomas Heller <theller at ctypes.org> added the comment:

> The __slots__ member of a class object has the same behavior.
> You may mutate it (even replace it) but this has no effect: only the
> value available when the "class" statement was executed is relevant.

The rules in ctypes are a little bit more complicated (but thanks for the
__slots__ example, Amaury):

The _fields_ sequence is used when the class statement is executed (if
_fields_ are given), or when _fields_ are assigned to the class.
The third case appears when an instance of a structure class without _fields_
is actually *used*: by creating an instance of the class, by using the
class in another structure _fields_ definition; in this case the structure class
is built with an empty _fields_ list.

To answer the OP quetsions:  Yes, disallowing lists as _fields_ would break
too much code.  Also, I think tuples in lists are easier to read than nested tuples.

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2680>
__________________________________


More information about the Python-bugs-list mailing list