Skip to content

Commit 494b836

Browse files
committed
Fix as_dict for arrays
If the field is an array, then the field type will not have the as_dict method bound to it. The Structure describing the individual elements in the array will have the as_dict method. Because of this, hasattr(type_, "as_dict") will always return False.
1 parent 0df7325 commit 494b836

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

ctypeslib/data/structure_type.tpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ class AsDictMixin:
1717
type_ = type(value)
1818
if hasattr(value, "_length_") and hasattr(value, "_type_"):
1919
# array
20-
if not hasattr(type_, "as_dict"):
21-
value = [v for v in value]
22-
else:
23-
type_ = type_._type_
20+
type_ = type_._type_
21+
if hasattr(type_, 'as_dict'):
2422
value = [type_.as_dict(v) for v in value]
23+
else:
24+
value = [i for i in value]
2525
elif hasattr(value, "contents") and hasattr(value, "_type_"):
2626
# pointer
2727
try:

0 commit comments

Comments
 (0)