mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
bpo-36492: Deprecate passing some arguments as keyword arguments. (GH-12637)
Deprecated passing the following arguments as keyword arguments: - "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 the create() method of multiprocessing.managers.Server and multiprocessing.managers.SharedMemoryServer. - "obj" in weakref.finalize(). Also allowed to pass arbitrary keyword arguments (even "self" and "func") if the above arguments are passed as positional argument.
This commit is contained in:
parent
5f2c50810a
commit
42a139ed88
22 changed files with 457 additions and 21 deletions
|
|
@ -49,6 +49,9 @@ INITIALIZER_STATUS = 'uninitialized'
|
|||
def mul(x, y):
|
||||
return x * y
|
||||
|
||||
def capture(*args, **kwargs):
|
||||
return args, kwargs
|
||||
|
||||
def sleep_and_raise(t):
|
||||
time.sleep(t)
|
||||
raise Exception('this is an exception')
|
||||
|
|
@ -658,6 +661,13 @@ class ExecutorTest:
|
|||
def test_submit_keyword(self):
|
||||
future = self.executor.submit(mul, 2, y=8)
|
||||
self.assertEqual(16, future.result())
|
||||
future = self.executor.submit(capture, 1, self=2, fn=3)
|
||||
self.assertEqual(future.result(), ((1,), {'self': 2, 'fn': 3}))
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
future = self.executor.submit(fn=capture, arg=1)
|
||||
self.assertEqual(future.result(), ((), {'arg': 1}))
|
||||
with self.assertRaises(TypeError):
|
||||
self.executor.submit(arg=1)
|
||||
|
||||
def test_map(self):
|
||||
self.assertEqual(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue