Skip to content

Commit

Permalink
Set singles mask only if already present on the enum
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nicholasjng committed Sep 19, 2024
1 parent 7f7e0c0 commit 07edca1
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/nb_enum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")());
Expand Down

0 comments on commit 07edca1

Please sign in to comment.