Skip to content

Commit 9577395

Browse files
Remove unused exceptions, fix pep 8 formatting errors and fix _NOT_SET in recv_nowait()
1 parent 049aa3a commit 9577395

File tree

3 files changed

+16
-32
lines changed

3 files changed

+16
-32
lines changed

Lib/test/support/interpreters.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
"""Subinterpreters High Level Module."""
22

33
import _xxsubinterpreters as _interpreters
4+
45
# aliases:
56
from _xxsubinterpreters import (
6-
ChannelError, ChannelNotFoundError,
7-
ChannelEmptyError, ChannelNotEmptyError, NotReceivedError,
7+
ChannelError, ChannelNotFoundError, ChannelEmptyError,
88
is_shareable,
99
)
1010

11+
1112
__all__ = [
1213
'Interpreter', 'get_current', 'get_main', 'create', 'list_all',
1314
'SendChannel', 'RecvChannel',
1415
'create_channel', 'list_all_channels', 'is_shareable',
1516
'ChannelError', 'ChannelNotFoundError',
16-
'ChannelEmptyError', 'ChannelNotEmptyError',
17-
'NotReceivedError',
17+
'ChannelEmptyError',
1818
]
1919

2020

@@ -25,20 +25,23 @@ def create(*, isolated=True):
2525
id = _interpreters.create(isolated=isolated)
2626
return Interpreter(id, isolated=isolated)
2727

28+
2829
def list_all():
2930
"""
3031
Get all existing interpreters.
3132
"""
3233
return [Interpreter(id) for id in
3334
_interpreters.list_all()]
3435

36+
3537
def get_current():
3638
"""
3739
Get the currently running interpreter.
3840
"""
3941
id = _interpreters.get_current()
4042
return Interpreter(id)
4143

44+
4245
def get_main():
4346
"""
4447
Get the main interpreter.
@@ -100,6 +103,7 @@ def create_channel():
100103
cid = _interpreters.channel_create()
101104
return (RecvChannel(cid), SendChannel(cid))
102105

106+
103107
def list_all_channels():
104108
"""
105109
Get all open channels.
@@ -108,6 +112,9 @@ def list_all_channels():
108112
for cid in _interpreters.channel_list_all()]
109113

110114

115+
_NOT_SET = object()
116+
117+
111118
class RecvChannel:
112119
"""
113120
The RecvChannel object represents
@@ -131,22 +138,19 @@ def recv(self, *, _delay=10 / 1000): # 10 milliseconds
131138
obj = _interpreters.channel_recv(self._id, sentinel)
132139
return obj
133140

134-
def recv_nowait(self, default=None):
141+
def recv_nowait(self, default=_NOT_SET):
135142
"""
136143
Like recv(), but return the default
137144
instead of waiting.
138145
139146
This function is blocked by a missing low-level
140147
implementation of channel_recv_wait().
141148
"""
142-
if default is None:
143-
default = _NOT_SET
144149
if default is _NOT_SET:
145150
return _interpreters.channel_recv(self._id)
146151
else:
147152
return _interpreters.channel_recv(self._id, default)
148153

149-
_NOT_SET = object()
150154

151155
class SendChannel:
152156
"""

Lib/test/test_interpreters.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import _xxsubinterpreters as _interpreters
99
from test.support import interpreters
1010

11+
1112
def _captured_script(script):
1213
r, w = os.pipe()
1314
indented = script.replace('\n', '\n ')
@@ -19,6 +20,7 @@ def _captured_script(script):
1920
""")
2021
return wrapped, open(r)
2122

23+
2224
def clean_up_interpreters():
2325
for interp in interpreters.list_all():
2426
if interp.id == 0: # main
@@ -28,12 +30,14 @@ def clean_up_interpreters():
2830
except RuntimeError:
2931
pass # already destroyed
3032

33+
3134
def _run_output(interp, request, shared=None):
3235
script, rpipe = _captured_script(request)
3336
with rpipe:
3437
interp.run(script)
3538
return rpipe.read()
3639

40+
3741
@contextlib.contextmanager
3842
def _running(interp):
3943
r, w = os.pipe()
@@ -519,7 +523,6 @@ def test_send_recv_nowait_same_interpreter(self):
519523
assert obj == orig
520524
"""))
521525

522-
523526
r, s = interpreters.create_channel()
524527

525528
def f():

Modules/_xxsubinterpretersmodule.c

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,8 +1167,6 @@ static PyObject *ChannelNotFoundError;
11671167
static PyObject *ChannelClosedError;
11681168
static PyObject *ChannelEmptyError;
11691169
static PyObject *ChannelNotEmptyError;
1170-
static PyObject *ChannelReleasedError;
1171-
static PyObject *NotReceivedError;
11721170

11731171
static int
11741172
channel_exceptions_init(PyObject *ns)
@@ -1205,27 +1203,6 @@ channel_exceptions_init(PyObject *ns)
12051203
return -1;
12061204
}
12071205

1208-
// An operation tried to use a released channel.
1209-
ChannelReleasedError = PyErr_NewException(
1210-
"_interpreters.ChannelReleasedError", ChannelClosedError, NULL);
1211-
if (ChannelReleasedError == NULL) {
1212-
return -1;
1213-
}
1214-
if (PyDict_SetItemString(ns, "ChannelReleasedError", ChannelReleasedError) != 0) {
1215-
return -1;
1216-
}
1217-
1218-
// An operation trying to send an object when Nothing was waiting
1219-
// to receive it
1220-
NotReceivedError = PyErr_NewException(
1221-
"_interpreters.NotReceivedError", ChannelError, NULL);
1222-
if (NotReceivedError == NULL) {
1223-
return -1;
1224-
}
1225-
if (PyDict_SetItemString(ns, "NotReceivedError", NotReceivedError) != 0) {
1226-
return -1;
1227-
}
1228-
12291206
// An operation tried to pop from an empty channel.
12301207
ChannelEmptyError = PyErr_NewException(
12311208
"_xxsubinterpreters.ChannelEmptyError", ChannelError, NULL);

0 commit comments

Comments
 (0)