Skip to content

Commit fd42572

Browse files
_interpreters.bind() -> _interpreters.set___main___attrs()
1 parent d31cbb2 commit fd42572

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
@@ -656,7 +656,7 @@ def test_shareable_types(self):
656656
]
657657
for obj in objects:
658658
with self.subTest(obj):
659-
interpreters.bind(interp, dict(obj=obj))
659+
interpreters.set___main___attrs(interp, dict(obj=obj))
660660
interpreters.run_string(
661661
interp,
662662
f'assert(obj == {obj!r})',
@@ -787,7 +787,7 @@ def test_with_shared(self):
787787
with open({w}, 'wb') as chan:
788788
pickle.dump(ns, chan)
789789
""")
790-
interpreters.bind(self.id, shared)
790+
interpreters.set___main___attrs(self.id, shared)
791791
interpreters.run_string(self.id, script)
792792
with open(r, 'rb') as chan:
793793
ns = pickle.load(chan)
@@ -809,7 +809,7 @@ def test_shared_overwrites(self):
809809
ns2 = dict(vars())
810810
del ns2['__builtins__']
811811
""")
812-
interpreters.bind(self.id, shared)
812+
interpreters.set___main___attrs(self.id, shared)
813813
interpreters.run_string(self.id, script)
814814

815815
r, w = os.pipe()
@@ -841,7 +841,7 @@ def test_shared_overwrites_default_vars(self):
841841
with open({w}, 'wb') as chan:
842842
pickle.dump(ns, chan)
843843
""")
844-
interpreters.bind(self.id, shared)
844+
interpreters.set___main___attrs(self.id, shared)
845845
interpreters.run_string(self.id, script)
846846
with open(r, 'rb') as chan:
847847
ns = pickle.load(chan)
@@ -948,7 +948,7 @@ def script():
948948
with open(w, 'w', encoding="utf-8") as spipe:
949949
with contextlib.redirect_stdout(spipe):
950950
print('it worked!', end='')
951-
interpreters.bind(self.id, dict(w=w))
951+
interpreters.set___main___attrs(self.id, dict(w=w))
952952
interpreters.run_func(self.id, script)
953953

954954
with open(r, encoding="utf-8") as outfile:
@@ -965,7 +965,7 @@ def script():
965965
with contextlib.redirect_stdout(spipe):
966966
print('it worked!', end='')
967967
def f():
968-
interpreters.bind(self.id, dict(w=w))
968+
interpreters.set___main___attrs(self.id, dict(w=w))
969969
interpreters.run_func(self.id, script)
970970
t = threading.Thread(target=f)
971971
t.start()
@@ -986,7 +986,7 @@ def script():
986986
with contextlib.redirect_stdout(spipe):
987987
print('it worked!', end='')
988988
code = script.__code__
989-
interpreters.bind(self.id, dict(w=w))
989+
interpreters.set___main___attrs(self.id, dict(w=w))
990990
interpreters.run_func(self.id, code)
991991

992992
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)