[3.7] bpo-36492: Fix passing special keyword arguments to some functions. (GH-12637) (GH-12645)
The following arguments can be passed as keyword arguments for passing
to other function if the corresponding required argument is passed as
positional:
- "func" in functools.partialmethod(), weakref.finalize(),
profile.Profile.runcall(), cProfile.Profile.runcall(),
bdb.Bdb.runcall(), trace.Trace.runfunc() and
curses.wrapper().
- "function" in unittest.addModuleCleanup() and
unittest.TestCase.addCleanup().
- "fn" in the submit() method of concurrent.futures.ThreadPoolExecutor
and concurrent.futures.ProcessPoolExecutor.
- "callback" in contextlib.ExitStack.callback(),
contextlib.AsyncExitStack.callback() and
contextlib.AsyncExitStack.push_async_callback().
- "c" and "typeid" in multiprocessing.managers.Server.create().
- "obj" in weakref.finalize().
(cherry picked from commit 42a139ed88c487f325a241c6ee8b308b3c045975)
diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py
index 2a44404..30c2e27 100644
--- a/Lib/test/test_contextlib.py
+++ b/Lib/test/test_contextlib.py
@@ -575,6 +575,7 @@
((), dict(example=1)),
((1,), dict(example=1)),
((1,2), dict(example=1)),
+ ((1,2), dict(self=3, callback=4)),
]
result = []
def _exit(*args, **kwds):
@@ -597,6 +598,15 @@
self.assertIsNone(wrapper[1].__doc__, _exit.__doc__)
self.assertEqual(result, expected)
+ result = []
+ with self.exit_stack() as stack:
+ with self.assertRaises(TypeError):
+ stack.callback(arg=1)
+ with self.assertRaises(TypeError):
+ self.exit_stack.callback(arg=2)
+ stack.callback(callback=_exit, arg=3)
+ self.assertEqual(result, [((), {'arg': 3})])
+
def test_push(self):
exc_raised = ZeroDivisionError
def _expect_exc(exc_type, exc, exc_tb):