Skip to content

Commit

Permalink
Support hex constants in enums (GH-5525)
Browse files Browse the repository at this point in the history
And other "special" integer constants.

Fixes #5524
  • Loading branch information
da-woods committed Jul 12, 2023
1 parent 0c6141a commit 864e563
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Cython/Compiler/Nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from . import Options
from . import DebugFlags
from .Pythran import has_np_pythran, pythran_type, is_pythran_buffer
from ..Utils import add_metaclass
from ..Utils import add_metaclass, str_to_number


if sys.version_info[0] >= 3:
Expand Down Expand Up @@ -1783,7 +1783,7 @@ def analyse_enum_declarations(self, env, enum_entry, incremental_int_value):
enum_value = incremental_int_value
if self.value:
if self.value.is_literal:
enum_value = int(self.value.value)
enum_value = str_to_number(self.value.value)
elif (self.value.is_name or self.value.is_attribute) and self.value.entry:
enum_value = self.value.entry.enum_int_value
else:
Expand Down
2 changes: 1 addition & 1 deletion tests/run/cpdef_enums.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ cdef extern from *:

cpdef enum CyDefinedHasDuplicates1:
CY_DUP1_A
CY_DUP1_B = 0
CY_DUP1_B = 0x00000000


cpdef enum CyDefinedHasDuplicates2:
Expand Down

0 comments on commit 864e563

Please sign in to comment.