From 494b8364c07afdd5ddb3afac5de2aca073f9dbb2 Mon Sep 17 00:00:00 2001 From: Faisal Shah Date: Fri, 7 Jun 2024 12:29:24 -0500 Subject: [PATCH] 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. --- ctypeslib/data/structure_type.tpl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ctypeslib/data/structure_type.tpl b/ctypeslib/data/structure_type.tpl index 5c08ffb..d44a4b4 100644 --- a/ctypeslib/data/structure_type.tpl +++ b/ctypeslib/data/structure_type.tpl @@ -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: