Skip to content

Commit

Permalink
Fix as_dict for arrays
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
faisal-shah committed Aug 7, 2024
1 parent 0df7325 commit 494b836
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ctypeslib/data/structure_type.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ class AsDictMixin:
type_ = type(value)
if hasattr(value, "_length_") and hasattr(value, "_type_"):
# array
if not hasattr(type_, "as_dict"):
value = [v for v in value]
else:
type_ = type_._type_
type_ = type_._type_
if hasattr(type_, 'as_dict'):
value = [type_.as_dict(v) for v in value]
else:
value = [i for i in value]
elif hasattr(value, "contents") and hasattr(value, "_type_"):
# pointer
try:
Expand Down

0 comments on commit 494b836

Please sign in to comment.