Skip to content

Commit 3925f57

Browse files
authored
Set singles mask only if already present on the enum (#727)
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.
1 parent e67d934 commit 3925f57

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/nb_enum.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void enum_append(PyObject *tp_, const char *name_, int64_t value_,
126126
setattr(tp, "_flag_mask_", tp.attr("_flag_mask_") | val);
127127

128128
bool is_single_bit = (value_ != 0) && (value_ & (value_ - 1)) == 0;
129-
if (is_single_bit)
129+
if (is_single_bit && hasattr(tp, "_singles_mask_"))
130130
setattr(tp, "_singles_mask_", tp.attr("_singles_mask_") | val);
131131

132132
int_ bit_length = int_(tp.attr("_flag_mask_").attr("bit_length")());

0 commit comments

Comments
 (0)