diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2019-04-01 10:59:24 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-01 10:59:24 +0300 |
commit | a37f356de19828241bf19129f804369794c72ed3 (patch) | |
tree | 8d91421e049ae0a2781ff6c5b3a2352c3ec89071 /Lib/functools.py | |
parent | 5e233951d931acc0e927100c51e9a27a2791b6a5 (diff) | |
download | cpython-git-a37f356de19828241bf19129f804369794c72ed3.tar.gz |
[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)
Diffstat (limited to 'Lib/functools.py')
-rw-r--r-- | Lib/functools.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/Lib/functools.py b/Lib/functools.py index b734899b56..1daa1d1775 100644 --- a/Lib/functools.py +++ b/Lib/functools.py @@ -323,7 +323,20 @@ class partialmethod(object): callables as instance methods. """ - def __init__(self, func, *args, **keywords): + def __init__(*args, **keywords): + if len(args) >= 2: + self, func, *args = args + elif not args: + raise TypeError("descriptor '__init__' of partialmethod " + "needs an argument") + elif 'func' in keywords: + func = keywords.pop('func') + self, *args = args + else: + raise TypeError("type 'partialmethod' takes at least one argument, " + "got %d" % (len(args)-1)) + args = tuple(args) + if not callable(func) and not hasattr(func, "__get__"): raise TypeError("{!r} is not callable or a descriptor" .format(func)) |