Skip to content

Commit 320daec

Browse files
committed
Make hack used in debug_options slightly cleaner
1 parent f48da11 commit 320daec

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/sage/structure/debug_options.pyx

+10-8
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ cdef class DebugOptions_class:
4141

4242
cdef DebugOptions_class debug = DebugOptions_class()
4343

44-
# Since "debug" is declared with a type, it can only be cimported at
44+
# Since "debug" is declared with cdef, it can only be cimported at
4545
# the Cython level, not imported in plain Python. So we add it to the
46-
# globals manually. We need to hack into Cython internals for this
47-
# since Sage is compiled with the old_style_globals option.
48-
from cpython.object cimport PyObject
49-
cdef extern from *:
50-
PyObject* __pyx_d
51-
52-
(<object>__pyx_d)["debug"] = debug
46+
# globals manually. However this will make the variable out of sync
47+
# if some user modifies the object, which is inevitable.
48+
# See https://github.com/cython/cython/issues/3959#issuecomment-753455240
49+
# and https://github.com/cython/cython/issues/656
50+
# Note that ``_this_module`` could not be ``globals()``
51+
# because Sage is compiled with the old_style_globals option.
52+
import sage.structure.debug_options as _this_module
53+
_this_module.debug = debug
54+
del _this_module

0 commit comments

Comments
 (0)