mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48: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
|
@ -358,10 +358,36 @@ class Server(object):
|
|||
finally:
|
||||
self.stop_event.set()
|
||||
|
||||
def create(self, c, typeid, *args, **kwds):
|
||||
def create(*args, **kwds):
|
||||
'''
|
||||
Create a new shared object and return its id
|
||||
'''
|
||||
if len(args) >= 3:
|
||||
self, c, typeid, *args = args
|
||||
elif not args:
|
||||
raise TypeError("descriptor 'create' of 'Server' object "
|
||||
"needs an argument")
|
||||
else:
|
||||
if 'typeid' not in kwds:
|
||||
raise TypeError('create expected at least 2 positional '
|
||||
'arguments, got %d' % (len(args)-1))
|
||||
typeid = kwds.pop('typeid')
|
||||
if len(args) >= 2:
|
||||
self, c, *args = args
|
||||
import warnings
|
||||
warnings.warn("Passing 'typeid' as keyword argument is deprecated",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
else:
|
||||
if 'c' not in kwds:
|
||||
raise TypeError('create expected at least 2 positional '
|
||||
'arguments, got %d' % (len(args)-1))
|
||||
c = kwds.pop('c')
|
||||
self, *args = args
|
||||
import warnings
|
||||
warnings.warn("Passing 'c' as keyword argument is deprecated",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
args = tuple(args)
|
||||
|
||||
with self.mutex:
|
||||
callable, exposed, method_to_typeid, proxytype = \
|
||||
self.registry[typeid]
|
||||
|
@ -583,10 +609,13 @@ class BaseManager(object):
|
|||
util.info('manager serving at %r', server.address)
|
||||
server.serve_forever()
|
||||
|
||||
def _create(self, typeid, *args, **kwds):
|
||||
def _create(*args, **kwds):
|
||||
'''
|
||||
Create a new shared object; return the token and exposed tuple
|
||||
'''
|
||||
self, typeid, *args = args
|
||||
args = tuple(args)
|
||||
|
||||
assert self._state.value == State.STARTED, 'server not yet started'
|
||||
conn = self._Client(self._address, authkey=self._authkey)
|
||||
try:
|
||||
|
@ -1261,15 +1290,25 @@ if HAS_SHMEM:
|
|||
_SharedMemoryTracker(f"shmm_{self.address}_{getpid()}")
|
||||
util.debug(f"SharedMemoryServer started by pid {getpid()}")
|
||||
|
||||
def create(self, c, typeid, *args, **kwargs):
|
||||
def create(*args, **kwargs):
|
||||
"""Create a new distributed-shared object (not backed by a shared
|
||||
memory block) and return its id to be used in a Proxy Object."""
|
||||
# Unless set up as a shared proxy, don't make shared_memory_context
|
||||
# a standard part of kwargs. This makes things easier for supplying
|
||||
# simple functions.
|
||||
if len(args) >= 3:
|
||||
typeod = args[2]
|
||||
elif 'typeid' in kwargs:
|
||||
typeid = kwargs['typeid']
|
||||
elif not args:
|
||||
raise TypeError("descriptor 'create' of 'SharedMemoryServer' "
|
||||
"object needs an argument")
|
||||
else:
|
||||
raise TypeError('create expected at least 2 positional '
|
||||
'arguments, got %d' % (len(args)-1))
|
||||
if hasattr(self.registry[typeid][-1], "_shared_memory_proxy"):
|
||||
kwargs['shared_memory_context'] = self.shared_memory_context
|
||||
return Server.create(self, c, typeid, *args, **kwargs)
|
||||
return Server.create(*args, **kwargs)
|
||||
|
||||
def shutdown(self, c):
|
||||
"Call unlink() on all tracked shared memory, terminate the Server."
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue