diff --git a/integration_test/Bindings/Python/support/conversion.py b/integration_test/Bindings/Python/support/conversion.py new file mode 100644 index 000000000000..2dc67c0c4d36 --- /dev/null +++ b/integration_test/Bindings/Python/support/conversion.py @@ -0,0 +1,12 @@ +# REQUIRES: bindings_python +# RUN: %PYTHON% %s | FileCheck %s + +from circt.ir import ArrayAttr, Context, StringAttr +from circt.support import attribute_to_var + +with Context(): + string_attr = StringAttr.get("foo") + array_attr = ArrayAttr.get([string_attr]) + array = attribute_to_var(array_attr) + # CHECK: ['foo'] + print(array) diff --git a/lib/Bindings/Python/support.py b/lib/Bindings/Python/support.py index ba7bbbdc8113..bcf248b947b7 100644 --- a/lib/Bindings/Python/support.py +++ b/lib/Bindings/Python/support.py @@ -131,7 +131,7 @@ def attribute_to_var(attr): # If it's not the root type, assume it's already been downcasted and don't do # the expensive probing below. - if attr.__class__ != ir.Attribute: + if attr.__class__ != ir.Attribute and hasattr(attr, "value"): return attr.value from .dialects import hw, om