Skip to content

gh-76785: Add Interpreter.prepare_main() #113021

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
bind() -> prepare_main()
  • Loading branch information
ericsnowcurrently committed Dec 12, 2023
commit c32eff3758423ffe7f166f7746c74d02483bcdf5
3 changes: 1 addition & 2 deletions Lib/test/support/interpreters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ def close(self):
"""
return _interpreters.destroy(self._id)

# XXX setattr?
def bind(self, ns=None, /, **kwargs):
def prepare_main(self, ns=None, /, **kwargs):
"""Bind the given values into the interpreter's __main__.

The values must be shareable.
Expand Down
14 changes: 7 additions & 7 deletions Lib/test/test_interpreters/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,17 +452,17 @@ def task():
self.assertEqual(os.read(r_interp, 1), FINISHED)


class TestInterpreterBind(TestBase):
class TestInterpreterPrepareMain(TestBase):

def test_empty(self):
interp = interpreters.create()
with self.assertRaises(ValueError):
interp.bind()
interp.prepare_main()

def test_dict(self):
values = {'spam': 42, 'eggs': 'ham'}
interp = interpreters.create()
interp.bind(values)
interp.prepare_main(values)
out = _run_output(interp, dedent("""
print(spam, eggs)
"""))
Expand All @@ -472,7 +472,7 @@ def test_tuple(self):
values = {'spam': 42, 'eggs': 'ham'}
values = tuple(values.items())
interp = interpreters.create()
interp.bind(values)
interp.prepare_main(values)
out = _run_output(interp, dedent("""
print(spam, eggs)
"""))
Expand All @@ -481,7 +481,7 @@ def test_tuple(self):
def test_kwargs(self):
values = {'spam': 42, 'eggs': 'ham'}
interp = interpreters.create()
interp.bind(**values)
interp.prepare_main(**values)
out = _run_output(interp, dedent("""
print(spam, eggs)
"""))
Expand All @@ -490,7 +490,7 @@ def test_kwargs(self):
def test_dict_and_kwargs(self):
values = {'spam': 42, 'eggs': 'ham'}
interp = interpreters.create()
interp.bind(values, foo='bar')
interp.prepare_main(values, foo='bar')
out = _run_output(interp, dedent("""
print(spam, eggs, foo)
"""))
Expand All @@ -500,7 +500,7 @@ def test_not_shareable(self):
interp = interpreters.create()
# XXX TypeError?
with self.assertRaises(ValueError):
interp.bind(spam={'spam': 'eggs', 'foo': 'bar'})
interp.prepare_main(spam={'spam': 'eggs', 'foo': 'bar'})

# Make sure neither was actually bound.
with self.assertRaises(interpreters.ExecFailure):
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_interpreters/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def _run_output(interp, request, init=None):
script, rpipe = _captured_script(request)
with rpipe:
if init:
interp.bind(init)
interp.prepare_main(init)
interp.exec_sync(script)
return rpipe.read()

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy