From 864e56359a83125ab9f89450b385099f1cf6da7f Mon Sep 17 00:00:00 2001 From: da-woods Date: Wed, 12 Jul 2023 09:28:25 +0100 Subject: [PATCH] Support hex constants in enums (GH-5525) And other "special" integer constants. Fixes https://github.com/cython/cython/issues/5524 --- Cython/Compiler/Nodes.py | 4 ++-- tests/run/cpdef_enums.pyx | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 857aa0fa49f..16fd204709a 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -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: @@ -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: diff --git a/tests/run/cpdef_enums.pyx b/tests/run/cpdef_enums.pyx index 2c30ab7c0b3..83b813eb841 100644 --- a/tests/run/cpdef_enums.pyx +++ b/tests/run/cpdef_enums.pyx @@ -106,7 +106,7 @@ cdef extern from *: cpdef enum CyDefinedHasDuplicates1: CY_DUP1_A - CY_DUP1_B = 0 + CY_DUP1_B = 0x00000000 cpdef enum CyDefinedHasDuplicates2: