Skip to content

Commit 067ebbd

Browse files
author
Release Manager
committed
gh-39093: Improve hack used in debug_options The `__pyx_d` no longer works in newer cython versions. This should works better. ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [x] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - #12345: short description why this is a dependency --> <!-- - #34567: ... --> URL: #39093 Reported by: user202729 Reviewer(s): Kwankyu Lee
2 parents a89c57b + 3e6d549 commit 067ebbd

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/sage/structure/debug_options.pyx

Lines changed: 10 additions & 8 deletions
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)