diff --git a/src/sage/structure/debug_options.pyx b/src/sage/structure/debug_options.pyx index 78e12faa0ce..a906278715a 100644 --- a/src/sage/structure/debug_options.pyx +++ b/src/sage/structure/debug_options.pyx @@ -41,12 +41,14 @@ cdef class DebugOptions_class: cdef DebugOptions_class debug = DebugOptions_class() -# Since "debug" is declared with a type, it can only be cimported at +# Since "debug" is declared with cdef, it can only be cimported at # the Cython level, not imported in plain Python. So we add it to the -# globals manually. We need to hack into Cython internals for this -# since Sage is compiled with the old_style_globals option. -from cpython.object cimport PyObject -cdef extern from *: - PyObject* __pyx_d - -(__pyx_d)["debug"] = debug +# globals manually. However this will make the variable out of sync +# if some user modifies the object, which is inevitable. +# See https://github.com/cython/cython/issues/3959#issuecomment-753455240 +# and https://github.com/cython/cython/issues/656 +# Note that ``_this_module`` could not be ``globals()`` +# because Sage is compiled with the old_style_globals option. +import sage.structure.debug_options as _this_module +_this_module.debug = debug +del _this_module