@@ -15,11 +15,9 @@ cdef class Handle:
15
15
self ._source_traceback = extract_stack()
16
16
17
17
cdef inline _set_context(self , object context):
18
- cdef PyContext* current_context
19
-
20
18
if PY37:
21
19
if context is None :
22
- context = copy_current_context ()
20
+ context = Context_CopyCurrent ()
23
21
self .context = context
24
22
else :
25
23
if context is not None :
@@ -54,7 +52,7 @@ cdef class Handle:
54
52
try :
55
53
if PY37:
56
54
assert self .context is not None
57
- PyContext_Enter( < PyContext * > self .context)
55
+ Context_Enter( self .context)
58
56
59
57
if cb_type == 1 :
60
58
callback = self .arg1
@@ -103,7 +101,7 @@ cdef class Handle:
103
101
context = self .context
104
102
Py_DECREF(self )
105
103
if PY37:
106
- PyContext_Exit( < PyContext * > context)
104
+ Context_Exit( context)
107
105
108
106
cdef _cancel(self ):
109
107
self ._cancelled = 1
@@ -181,7 +179,7 @@ cdef class TimerHandle:
181
179
182
180
if PY37:
183
181
if context is None :
184
- context = copy_current_context ()
182
+ context = Context_CopyCurrent ()
185
183
self .context = context
186
184
else :
187
185
if context is not None :
@@ -239,7 +237,7 @@ cdef class TimerHandle:
239
237
try :
240
238
if PY37:
241
239
assert self .context is not None
242
- PyContext_Enter( < PyContext * > self .context)
240
+ Context_Enter( self .context)
243
241
244
242
if args is not None :
245
243
callback(* args)
@@ -267,7 +265,7 @@ cdef class TimerHandle:
267
265
context = self .context
268
266
Py_DECREF(self )
269
267
if PY37:
270
- PyContext_Exit( < PyContext * > context)
268
+ Context_Exit( context)
271
269
272
270
# Public API
273
271
@@ -402,15 +400,3 @@ cdef extract_stack():
402
400
403
401
stack.reverse()
404
402
return stack
405
-
406
-
407
- cdef copy_current_context():
408
- cdef PyContext* current_context
409
-
410
- if PY37:
411
- current_context = PyContext_CopyCurrent()
412
- py_context = < object > current_context
413
- Py_XDECREF(< PyObject* > current_context)
414
- return py_context
415
-
416
- raise NotImplementedError (' "contextvars" support requires Python 3.7+' )
0 commit comments