Support full calls in interp_call(). · python/cpython@4327098 · GitHub
Skip to content

Commit 4327098

Browse files
Support full calls in interp_call().
1 parent 45d767c commit 4327098

5 files changed

Lines changed: 784 additions & 126 deletions

File tree

Lib/test/_code_definitions.py

Lines changed: 20 additions & 0 deletions

Lib/test/support/interpreters/__init__.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,13 @@ def exec(self, code, /):
226226
if excinfo is not None:
227227
raise ExecutionFailed(excinfo)
228228

229-
def call(self, callable, /):
229+
def _call(self, callable, args, kwargs):
230+
res, excinfo = _interpreters.call(self._id, callable, args, kwargs, restrict=True)
231+
if excinfo is not None:
232+
raise ExecutionFailed(excinfo)
233+
return res
234+
235+
def call(self, callable, /, *args, **kwargs):
230236
"""Call the object in the interpreter with given args/kwargs.
231237
232238
Only functions that take no arguments and have no closure
@@ -239,20 +245,13 @@ def call(self, callable, /):
239245
and an ExecutionFailed exception is raised, much like what
240246
happens with Interpreter.exec().
241247
"""
242-
# XXX Support args and kwargs.
243-
# XXX Support arbitrary callables.
244-
# XXX Support returning the return value (e.g. via pickle).
245-
excinfo = _interpreters.call(self._id, callable, restrict=True)
246-
if excinfo is not None:
247-
raise ExecutionFailed(excinfo)
248+
return self._call(callable, args, kwargs)
248249

249-
def call_in_thread(self, callable, /):
250+
def call_in_thread(self, callable, /, *args, **kwargs):
250251
"""Return a new thread that calls the object in the interpreter.
251252
252253
The return value and any raised exception are discarded.
253254
"""
254-
def task():
255-
self.call(callable)
256-
t = threading.Thread(target=task)
255+
t = threading.Thread(target=self._call, args=(callable, args, kwargs))
257256
t.start()
258257
return t

Lib/test/test_code.py

Lines changed: 46 additions & 2 deletions

0 commit comments

Comments
 (0)