Skip to content

Commit 8e99e66

Browse files
_interpreters.bind() -> _interpreters.set___main___attrs()
1 parent c8c2edd commit 8e99e66

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

Lib/test/support/interpreters.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,14 @@ def close(self):
103103
"""
104104
return _interpreters.destroy(self._id)
105105

106+
# XXX setattr?
106107
def bind(self, ns=None, /, **kwargs):
107-
"""Bind the given values into the interpreter's __main__."""
108+
"""Bind the given values into the interpreter's __main__.
109+
110+
The values must be shareable.
111+
"""
108112
ns = dict(ns, **kwargs) if ns is not None else kwargs
109-
_interpreters.bind(self._id, ns)
113+
_interpreters.set___main___attrs(self._id, ns)
110114

111115
# XXX Rename "run" to "exec"?
112116
# XXX Do not allow init to overwrite (by default)?

Lib/test/test__xxinterpchannels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ def test_run_string_arg_unresolved(self):
587587
cid = channels.create()
588588
interp = interpreters.create()
589589

590-
interpreters.bind(interp, dict(cid=cid.send))
590+
interpreters.set___main___attrs(interp, dict(cid=cid.send))
591591
out = _run_output(interp, dedent("""
592592
import _xxinterpchannels as _channels
593593
print(cid.end)

Lib/test/test__xxsubinterpreters.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ def test_shareable_types(self):
659659
]
660660
for obj in objects:
661661
with self.subTest(obj):
662-
interpreters.bind(interp, dict(obj=obj))
662+
interpreters.set___main___attrs(interp, dict(obj=obj))
663663
interpreters.run_string(
664664
interp,
665665
f'assert(obj == {obj!r})',
@@ -790,7 +790,7 @@ def test_with_shared(self):
790790
with open({w}, 'wb') as chan:
791791
pickle.dump(ns, chan)
792792
""")
793-
interpreters.bind(self.id, shared)
793+
interpreters.set___main___attrs(self.id, shared)
794794
interpreters.run_string(self.id, script)
795795
with open(r, 'rb') as chan:
796796
ns = pickle.load(chan)
@@ -812,7 +812,7 @@ def test_shared_overwrites(self):
812812
ns2 = dict(vars())
813813
del ns2['__builtins__']
814814
""")
815-
interpreters.bind(self.id, shared)
815+
interpreters.set___main___attrs(self.id, shared)
816816
interpreters.run_string(self.id, script)
817817

818818
r, w = os.pipe()
@@ -844,7 +844,7 @@ def test_shared_overwrites_default_vars(self):
844844
with open({w}, 'wb') as chan:
845845
pickle.dump(ns, chan)
846846
""")
847-
interpreters.bind(self.id, shared)
847+
interpreters.set___main___attrs(self.id, shared)
848848
interpreters.run_string(self.id, script)
849849
with open(r, 'rb') as chan:
850850
ns = pickle.load(chan)
@@ -951,7 +951,7 @@ def script():
951951
with open(w, 'w', encoding="utf-8") as spipe:
952952
with contextlib.redirect_stdout(spipe):
953953
print('it worked!', end='')
954-
interpreters.bind(self.id, dict(w=w))
954+
interpreters.set___main___attrs(self.id, dict(w=w))
955955
interpreters.run_func(self.id, script)
956956

957957
with open(r, encoding="utf-8") as outfile:
@@ -968,7 +968,7 @@ def script():
968968
with contextlib.redirect_stdout(spipe):
969969
print('it worked!', end='')
970970
def f():
971-
interpreters.bind(self.id, dict(w=w))
971+
interpreters.set___main___attrs(self.id, dict(w=w))
972972
interpreters.run_func(self.id, script)
973973
t = threading.Thread(target=f)
974974
t.start()
@@ -989,7 +989,7 @@ def script():
989989
with contextlib.redirect_stdout(spipe):
990990
print('it worked!', end='')
991991
code = script.__code__
992-
interpreters.bind(self.id, dict(w=w))
992+
interpreters.set___main___attrs(self.id, dict(w=w))
993993
interpreters.run_func(self.id, code)
994994

995995
with open(r, encoding="utf-8") as outfile:

Modules/_xxsubinterpretersmodule.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -403,10 +403,12 @@ PyDoc_STRVAR(get_main_doc,
403403
Return the ID of main interpreter.");
404404

405405
static PyObject *
406-
interp_bind(PyObject *self, PyObject *args)
406+
interp_set___main___attrs(PyObject *self, PyObject *args)
407407
{
408408
PyObject *id, *updates;
409-
if (!PyArg_ParseTuple(args, "OO:" MODULE_NAME ".bind", &id, &updates)) {
409+
if (!PyArg_ParseTuple(args, "OO:" MODULE_NAME ".set___main___attrs",
410+
&id, &updates))
411+
{
410412
return NULL;
411413
}
412414

@@ -449,8 +451,8 @@ interp_bind(PyObject *self, PyObject *args)
449451
Py_RETURN_NONE;
450452
}
451453

452-
PyDoc_STRVAR(bind_doc,
453-
"bind(id, ns)\n\
454+
PyDoc_STRVAR(set___main___attrs_doc,
455+
"set___main___attrs(id, ns)\n\
454456
\n\
455457
Bind the given attributes in the interpreter's __main__ module.");
456458

@@ -750,8 +752,8 @@ static PyMethodDef module_functions[] = {
750752
{"run_func", _PyCFunction_CAST(interp_run_func),
751753
METH_VARARGS | METH_KEYWORDS, run_func_doc},
752754

753-
{"bind", _PyCFunction_CAST(interp_bind),
754-
METH_VARARGS, bind_doc},
755+
{"set___main___attrs", _PyCFunction_CAST(interp_set___main___attrs),
756+
METH_VARARGS, set___main___attrs_doc},
755757
{"is_shareable", _PyCFunction_CAST(object_is_shareable),
756758
METH_VARARGS | METH_KEYWORDS, is_shareable_doc},
757759

0 commit comments

Comments
 (0)