From 07edca14a83e717a1c6fad62aca400ab78e973dc Mon Sep 17 00:00:00 2001 From: Nicholas Junge Date: Thu, 19 Sep 2024 07:47:02 +0200 Subject: [PATCH] Set singles mask only if already present on the enum The singles mask attribute was added for the STRICT boundary default, but only starting at Python 3.11.4. This means that for any Python 3.11 before that, we need to avoid updating it (accessing it in the process), which would result in an attribute error. --- src/nb_enum.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nb_enum.cpp b/src/nb_enum.cpp index 8e1ffa8c..47c344b8 100644 --- a/src/nb_enum.cpp +++ b/src/nb_enum.cpp @@ -126,7 +126,7 @@ void enum_append(PyObject *tp_, const char *name_, int64_t value_, setattr(tp, "_flag_mask_", tp.attr("_flag_mask_") | val); bool is_single_bit = (value_ != 0) && (value_ & (value_ - 1)) == 0; - if (is_single_bit) + if (is_single_bit && hasattr(tp, "_singles_mask_")) setattr(tp, "_singles_mask_", tp.attr("_singles_mask_") | val); int_ bit_length = int_(tp.attr("_flag_mask_").attr("bit_length")());