1010 ChannelEmptyError , ChannelNotEmptyError , # noqa: F401
1111)
1212from concurrent .interpreters ._crossinterp import (
13- UNBOUND_ERROR , UNBOUND_REMOVE ,
13+ UNBOUND , UNBOUND_ERROR , UNBOUND_REMOVE ,
1414)
1515
1616
@@ -28,20 +28,8 @@ class ItemInterpreterDestroyed(ChannelError,
2828 """Raised from get() and get_nowait()."""
2929
3030
31- UNBOUND = _crossinterp .UnboundItem .singleton ('queue' , __name__ )
32-
33-
34- def _serialize_unbound (unbound ):
35- if unbound is UNBOUND :
36- unbound = _crossinterp .UNBOUND
37- return _crossinterp .serialize_unbound (unbound )
38-
39-
4031def _resolve_unbound (flag ):
41- resolved = _crossinterp .resolve_unbound (flag , ItemInterpreterDestroyed )
42- if resolved is _crossinterp .UNBOUND :
43- resolved = UNBOUND
44- return resolved
32+ return _crossinterp .resolve_unbound (flag , ItemInterpreterDestroyed )
4533
4634
4735def create (* , unbounditems = UNBOUND ):
@@ -53,8 +41,9 @@ def create(*, unbounditems=UNBOUND):
5341 See SendChannel.send() for supported values. The default value
5442 is UNBOUND, which replaces the unbound item when received.
5543 """
56- unbound = _serialize_unbound (unbounditems )
57- unboundop , = unbound
44+ if unbounditems is None :
45+ raise TypeError (f'unbounditems must not be None' )
46+ unboundop = _crossinterp .unbound_to_flag (unbounditems )
5847 cid = _channels .create (unboundop , - 1 )
5948 recv , send = RecvChannel (cid ), SendChannel (cid )
6049 send ._set_unbound (unboundop , unbounditems )
@@ -179,17 +168,6 @@ class SendChannel(_ChannelEnd):
179168
180169 _end = 'send'
181170
182- # def __new__(cls, cid, *, _unbound=None):
183- # if _unbound is None:
184- # try:
185- # op = _channels.get_channel_defaults(cid)
186- # _unbound = (op,)
187- # except ChannelNotFoundError:
188- # _unbound = _serialize_unbound(UNBOUND)
189- # self = super().__new__(cls, cid)
190- # self._unbound = _unbound
191- # return self
192-
193171 def _set_unbound (self , op , items = None ):
194172 assert not hasattr (self , '_unbound' )
195173 if items is None :
@@ -219,10 +197,7 @@ def send(self, obj, timeout=None, *,
219197
220198 This blocks until the object is received.
221199 """
222- if unbounditems is None :
223- unboundop = - 1
224- else :
225- unboundop , = _serialize_unbound (unbounditems )
200+ unboundop = _crossinterp .unbound_to_flag (unbounditems )
226201 _channels .send (self ._id , obj , unboundop , timeout = timeout , blocking = True )
227202
228203 def send_nowait (self , obj , * ,
@@ -233,10 +208,7 @@ def send_nowait(self, obj, *,
233208 If the object is immediately received then return True
234209 (else False). Otherwise this is the same as send().
235210 """
236- if unbounditems is None :
237- unboundop = - 1
238- else :
239- unboundop , = _serialize_unbound (unbounditems )
211+ unboundop = _crossinterp .unbound_to_flag (unbounditems )
240212 # XXX Note that at the moment channel_send() only ever returns
241213 # None. This should be fixed when channel_send_wait() is added.
242214 # See bpo-32604 and gh-19829.
@@ -249,10 +221,7 @@ def send_buffer(self, obj, timeout=None, *,
249221
250222 This blocks until the object is received.
251223 """
252- if unbounditems is None :
253- unboundop = - 1
254- else :
255- unboundop , = _serialize_unbound (unbounditems )
224+ unboundop = _crossinterp .unbound_to_flag (unbounditems )
256225 _channels .send_buffer (self ._id , obj , unboundop ,
257226 timeout = timeout , blocking = True )
258227
@@ -264,10 +233,7 @@ def send_buffer_nowait(self, obj, *,
264233 If the object is immediately received then return True
265234 (else False). Otherwise this is the same as send().
266235 """
267- if unbounditems is None :
268- unboundop = - 1
269- else :
270- unboundop , = _serialize_unbound (unbounditems )
236+ unboundop = _crossinterp .unbound_to_flag (unbounditems )
271237 return _channels .send_buffer (self ._id , obj , unboundop , blocking = False )
272238
273239 def close (self ):
0 commit comments