Commit ef076d3a authored by Kirill Smelkov's avatar Kirill Smelkov

golang_test.pyx: Switch to cimport pychan

Change `from golang import chan` to `from golang cimport pychan`; add
type annotations where pychan is used. Using pychan at C level will be
needed when test code will need to access C-level pychan attributes.
parent 1bcb8297
...@@ -26,28 +26,28 @@ ...@@ -26,28 +26,28 @@
from __future__ import print_function, absolute_import from __future__ import print_function, absolute_import
from golang cimport go, panic, pypanic, topyexc from golang cimport go, pychan, panic, pypanic, topyexc
from golang import chan, nilchan from golang import nilchan
from golang import time from golang import time
# pylen_{recv,send}q returns len(ch._{recv,send}q) # pylen_{recv,send}q returns len(ch._{recv,send}q)
def pylen_recvq(ch): def pylen_recvq(pychan ch not None): # -> int
if ch is nilchan: if ch is nilchan:
raise AssertionError('len(.recvq) on nil channel') raise AssertionError('len(.recvq) on nil channel')
return len(ch._recvq) return len(ch._recvq)
def pylen_sendq(ch): def pylen_sendq(pychan ch not None): # -> int
if ch is nilchan: if ch is nilchan:
raise AssertionError('len(.sendq) on nil channel') raise AssertionError('len(.sendq) on nil channel')
return len(ch._sendq) return len(ch._sendq)
# pywaitBlocked waits till a receive or send channel operation blocks waiting on the channel. # pywaitBlocked waits till a receive or send pychan operation blocks waiting on the channel.
# #
# For example `pywaitBlocked(ch.send)` waits till sender blocks waiting on ch. # For example `pywaitBlocked(ch.send)` waits till sender blocks waiting on ch.
def pywaitBlocked(chanop): def pywaitBlocked(chanop):
if chanop.__self__.__class__ is not chan: if chanop.__self__.__class__ is not pychan:
pypanic("wait blocked: %r is method of a non-chan: %r" % (chanop, chanop.__self__.__class__)) pypanic("wait blocked: %r is method of a non-chan: %r" % (chanop, chanop.__self__.__class__))
ch = chanop.__self__ cdef pychan ch = chanop.__self__
recv = send = False recv = send = False
if chanop.__name__ == "recv": # XXX better check PyCFunction directly if chanop.__name__ == "recv": # XXX better check PyCFunction directly
recv = True recv = True
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment