[Python-checkins] [3.9] bpo-37116: Use PEP 570 syntax for positional-only parameters. (GH-12620)
Serhiy Storchaka
webhook-mailer at python.org
Wed Jun 5 11:22:39 EDT 2019
https://github.com/python/cpython/commit/142566c028720934325f0b7fe28680afd046e00f
commit: 142566c028720934325f0b7fe28680afd046e00f
branch: master
author: Serhiy Storchaka <storchaka at gmail.com>
committer: GitHub <noreply at github.com>
date: 2019-06-05T18:22:31+03:00
summary:
[3.9] bpo-37116: Use PEP 570 syntax for positional-only parameters. (GH-12620)
Turn deprecation warnings added in 3.8 into TypeError.
files:
M Doc/library/bdb.rst
M Doc/library/concurrent.futures.rst
M Doc/library/contextlib.rst
M Doc/library/curses.rst
M Doc/library/profile.rst
M Doc/library/trace.rst
M Doc/library/unittest.rst
M Doc/library/weakref.rst
M Lib/bdb.py
M Lib/cProfile.py
M Lib/collections/__init__.py
M Lib/concurrent/futures/_base.py
M Lib/concurrent/futures/process.py
M Lib/concurrent/futures/thread.py
M Lib/contextlib.py
M Lib/curses/__init__.py
M Lib/functools.py
M Lib/multiprocessing/managers.py
M Lib/profile.py
M Lib/test/test_concurrent_futures.py
M Lib/test/test_contextlib.py
M Lib/test/test_contextlib_async.py
M Lib/test/test_functools.py
M Lib/test/test_trace.py
M Lib/test/test_userdict.py
M Lib/test/test_weakref.py
M Lib/trace.py
M Lib/unittest/case.py
M Lib/unittest/test/test_runner.py
M Lib/weakref.py
diff --git a/Doc/library/bdb.rst b/Doc/library/bdb.rst
index 116ffcf88e3b..7e4066cd436a 100644
--- a/Doc/library/bdb.rst
+++ b/Doc/library/bdb.rst
@@ -343,7 +343,7 @@ The :mod:`bdb` module also defines two classes:
For backwards compatibility. Calls the :meth:`run` method.
- .. method:: runcall(func, *args, **kwds)
+ .. method:: runcall(func, /, *args, **kwds)
Debug a single function call, and return its result.
diff --git a/Doc/library/concurrent.futures.rst b/Doc/library/concurrent.futures.rst
index f2491dd24571..34905c449d7f 100644
--- a/Doc/library/concurrent.futures.rst
+++ b/Doc/library/concurrent.futures.rst
@@ -28,7 +28,7 @@ Executor Objects
An abstract class that provides methods to execute calls asynchronously. It
should not be used directly, but through its concrete subclasses.
- .. method:: submit(fn, *args, **kwargs)
+ .. method:: submit(fn, /, *args, **kwargs)
Schedules the callable, *fn*, to be executed as ``fn(*args **kwargs)``
and returns a :class:`Future` object representing the execution of the
diff --git a/Doc/library/contextlib.rst b/Doc/library/contextlib.rst
index 73b24e5f251a..0aa4ad765234 100644
--- a/Doc/library/contextlib.rst
+++ b/Doc/library/contextlib.rst
@@ -416,7 +416,7 @@ Functions and classes provided:
The passed in object is returned from the function, allowing this
method to be used as a function decorator.
- .. method:: callback(callback, *args, **kwds)
+ .. method:: callback(callback, /, *args, **kwds)
Accepts an arbitrary callback function and arguments and adds it to
the callback stack.
@@ -473,7 +473,7 @@ Functions and classes provided:
Similar to :meth:`push` but expects either an asynchronous context manager
or a coroutine function.
- .. method:: push_async_callback(callback, *args, **kwds)
+ .. method:: push_async_callback(callback, /, *args, **kwds)
Similar to :meth:`callback` but expects a coroutine function.
diff --git a/Doc/library/curses.rst b/Doc/library/curses.rst
index 7d1e7538a292..c88d3520e988 100644
--- a/Doc/library/curses.rst
+++ b/Doc/library/curses.rst
@@ -656,7 +656,7 @@ The module :mod:`curses` defines the following functions:
foreground color on the default background.
-.. function:: wrapper(func, ...)
+.. function:: wrapper(func, /, *args, **kwargs)
Initialize curses and call another callable object, *func*, which should be the
rest of your curses-using application. If the application raises an exception,
diff --git a/Doc/library/profile.rst b/Doc/library/profile.rst
index d8039fd28e0d..8d589d247b77 100644
--- a/Doc/library/profile.rst
+++ b/Doc/library/profile.rst
@@ -309,7 +309,7 @@ functions:
Profile the cmd via :func:`exec` with the specified global and
local environment.
- .. method:: runcall(func, *args, **kwargs)
+ .. method:: runcall(func, /, *args, **kwargs)
Profile ``func(*args, **kwargs)``
diff --git a/Doc/library/trace.rst b/Doc/library/trace.rst
index 85fec6830006..c2732d900bc1 100644
--- a/Doc/library/trace.rst
+++ b/Doc/library/trace.rst
@@ -166,7 +166,7 @@ Programmatic Interface
environments. If not defined, *globals* and *locals* default to empty
dictionaries.
- .. method:: runfunc(func, *args, **kwds)
+ .. method:: runfunc(func, /, *args, **kwds)
Call *func* with the given arguments under control of the :class:`Trace`
object with the current tracing parameters.
diff --git a/Doc/library/unittest.rst b/Doc/library/unittest.rst
index 5ec4b40856ae..320d898fc8d4 100644
--- a/Doc/library/unittest.rst
+++ b/Doc/library/unittest.rst
@@ -1427,7 +1427,7 @@ Test cases
:class:`TextTestResult` in Python 3.2.
- .. method:: addCleanup(function, *args, **kwargs)
+ .. method:: addCleanup(function, /, *args, **kwargs)
Add a function to be called after :meth:`tearDown` to cleanup resources
used during the test. Functions will be called in reverse order to the
diff --git a/Doc/library/weakref.rst b/Doc/library/weakref.rst
index a28d71060f38..a5c4295ef1fa 100644
--- a/Doc/library/weakref.rst
+++ b/Doc/library/weakref.rst
@@ -240,7 +240,7 @@ objects.
.. versionadded:: 3.4
-.. class:: finalize(obj, func, *args, **kwargs)
+.. class:: finalize(obj, func, /, *args, **kwargs)
Return a callable finalizer object which will be called when *obj*
is garbage collected. Unlike an ordinary weak reference, a finalizer
diff --git a/Lib/bdb.py b/Lib/bdb.py
index 96e7d18d718d..fd34976a4d0b 100644
--- a/Lib/bdb.py
+++ b/Lib/bdb.py
@@ -618,26 +618,11 @@ def runctx(self, cmd, globals, locals):
# This method is more useful to debug a single function call.
- def runcall(*args, **kwds):
+ def runcall(self, func, /, *args, **kwds):
"""Debug a single function call.
Return the result of the function call.
"""
- if len(args) >= 2:
- self, func, *args = args
- elif not args:
- raise TypeError("descriptor 'runcall' of 'Bdb' object "
- "needs an argument")
- elif 'func' in kwds:
- func = kwds.pop('func')
- self, *args = args
- import warnings
- warnings.warn("Passing 'func' as keyword argument is deprecated",
- DeprecationWarning, stacklevel=2)
- else:
- raise TypeError('runcall expected at least 1 positional argument, '
- 'got %d' % (len(args)-1))
-
self.reset()
sys.settrace(self.trace_dispatch)
res = None
@@ -649,7 +634,6 @@ def runcall(*args, **kwds):
self.quitting = True
sys.settrace(None)
return res
- runcall.__text_signature__ = '($self, func, /, *args, **kwds)'
def set_trace():
diff --git a/Lib/cProfile.py b/Lib/cProfile.py
index 369d02e22e24..4f202038d612 100755
--- a/Lib/cProfile.py
+++ b/Lib/cProfile.py
@@ -103,28 +103,12 @@ def runctx(self, cmd, globals, locals):
return self
# This method is more useful to profile a single function call.
- def runcall(*args, **kw):
- if len(args) >= 2:
- self, func, *args = args
- elif not args:
- raise TypeError("descriptor 'runcall' of 'Profile' object "
- "needs an argument")
- elif 'func' in kw:
- func = kw.pop('func')
- self, *args = args
- import warnings
- warnings.warn("Passing 'func' as keyword argument is deprecated",
- DeprecationWarning, stacklevel=2)
- else:
- raise TypeError('runcall expected at least 1 positional argument, '
- 'got %d' % (len(args)-1))
-
+ def runcall(self, func, /, *args, **kw):
self.enable()
try:
return func(*args, **kw)
finally:
self.disable()
- runcall.__text_signature__ = '($self, func, /, *args, **kw)'
def __enter__(self):
self.enable()
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py
index e9999e27d5f5..2264efe94a7d 100644
--- a/Lib/collections/__init__.py
+++ b/Lib/collections/__init__.py
@@ -971,28 +971,12 @@ def clear(self):
class UserDict(_collections_abc.MutableMapping):
# Start by filling-out the abstract methods
- def __init__(*args, **kwargs):
- if not args:
- raise TypeError("descriptor '__init__' of 'UserDict' object "
- "needs an argument")
- self, *args = args
- if len(args) > 1:
- raise TypeError('expected at most 1 arguments, got %d' % len(args))
- if args:
- dict = args[0]
- elif 'dict' in kwargs:
- dict = kwargs.pop('dict')
- import warnings
- warnings.warn("Passing 'dict' as keyword argument is deprecated",
- DeprecationWarning, stacklevel=2)
- else:
- dict = None
+ def __init__(self, dict=None, /, **kwargs):
self.data = {}
if dict is not None:
self.update(dict)
if kwargs:
self.update(kwargs)
- __init__.__text_signature__ = '($self, dict=None, /, **kwargs)'
def __len__(self): return len(self.data)
def __getitem__(self, key):
diff --git a/Lib/concurrent/futures/_base.py b/Lib/concurrent/futures/_base.py
index 6001e3bdb81b..fd0acec55d04 100644
--- a/Lib/concurrent/futures/_base.py
+++ b/Lib/concurrent/futures/_base.py
@@ -547,7 +547,7 @@ def set_exception(self, exception):
class Executor(object):
"""This is an abstract base class for concrete asynchronous executors."""
- def submit(*args, **kwargs):
+ def submit(self, fn, /, *args, **kwargs):
"""Submits a callable to be executed with the given arguments.
Schedules the callable to be executed as fn(*args, **kwargs) and returns
@@ -556,21 +556,7 @@ def submit(*args, **kwargs):
Returns:
A Future representing the given call.
"""
- if len(args) >= 2:
- pass
- elif not args:
- raise TypeError("descriptor 'submit' of 'Executor' object "
- "needs an argument")
- elif 'fn' in kwargs:
- import warnings
- warnings.warn("Passing 'fn' as keyword argument is deprecated",
- DeprecationWarning, stacklevel=2)
- else:
- raise TypeError('submit expected at least 1 positional argument, '
- 'got %d' % (len(args)-1))
-
raise NotImplementedError()
- submit.__text_signature__ = '($self, fn, /, *args, **kwargs)'
def map(self, fn, *iterables, timeout=None, chunksize=1):
"""Returns an iterator equivalent to map(fn, iter).
diff --git a/Lib/concurrent/futures/process.py b/Lib/concurrent/futures/process.py
index dd14eaec907d..cfdcd3ed7ea9 100644
--- a/Lib/concurrent/futures/process.py
+++ b/Lib/concurrent/futures/process.py
@@ -608,22 +608,7 @@ def _adjust_process_count(self):
p.start()
self._processes[p.pid] = p
- def submit(*args, **kwargs):
- if len(args) >= 2:
- self, fn, *args = args
- elif not args:
- raise TypeError("descriptor 'submit' of 'ProcessPoolExecutor' object "
- "needs an argument")
- elif 'fn' in kwargs:
- fn = kwargs.pop('fn')
- self, *args = args
- import warnings
- warnings.warn("Passing 'fn' as keyword argument is deprecated",
- DeprecationWarning, stacklevel=2)
- else:
- raise TypeError('submit expected at least 1 positional argument, '
- 'got %d' % (len(args)-1))
-
+ def submit(self, fn, /, *args, **kwargs):
with self._shutdown_lock:
if self._broken:
raise BrokenProcessPool(self._broken)
@@ -644,7 +629,6 @@ def submit(*args, **kwargs):
self._start_queue_management_thread()
return f
- submit.__text_signature__ = _base.Executor.submit.__text_signature__
submit.__doc__ = _base.Executor.submit.__doc__
def map(self, fn, *iterables, timeout=None, chunksize=1):
diff --git a/Lib/concurrent/futures/thread.py b/Lib/concurrent/futures/thread.py
index 2426e94de91f..75d05a76be3f 100644
--- a/Lib/concurrent/futures/thread.py
+++ b/Lib/concurrent/futures/thread.py
@@ -155,22 +155,7 @@ def __init__(self, max_workers=None, thread_name_prefix='',
self._initializer = initializer
self._initargs = initargs
- def submit(*args, **kwargs):
- if len(args) >= 2:
- self, fn, *args = args
- elif not args:
- raise TypeError("descriptor 'submit' of 'ThreadPoolExecutor' object "
- "needs an argument")
- elif 'fn' in kwargs:
- fn = kwargs.pop('fn')
- self, *args = args
- import warnings
- warnings.warn("Passing 'fn' as keyword argument is deprecated",
- DeprecationWarning, stacklevel=2)
- else:
- raise TypeError('submit expected at least 1 positional argument, '
- 'got %d' % (len(args)-1))
-
+ def submit(self, fn, /, *args, **kwargs):
with self._shutdown_lock:
if self._broken:
raise BrokenThreadPool(self._broken)
@@ -187,7 +172,6 @@ def submit(*args, **kwargs):
self._work_queue.put(w)
self._adjust_thread_count()
return f
- submit.__text_signature__ = _base.Executor.submit.__text_signature__
submit.__doc__ = _base.Executor.submit.__doc__
def _adjust_thread_count(self):
diff --git a/Lib/contextlib.py b/Lib/contextlib.py
index 94dc2bfed06c..69c272831a55 100644
--- a/Lib/contextlib.py
+++ b/Lib/contextlib.py
@@ -426,26 +426,11 @@ def enter_context(self, cm):
self._push_cm_exit(cm, _exit)
return result
- def callback(*args, **kwds):
+ def callback(self, callback, /, *args, **kwds):
"""Registers an arbitrary callback and arguments.
Cannot suppress exceptions.
"""
- if len(args) >= 2:
- self, callback, *args = args
- elif not args:
- raise TypeError("descriptor 'callback' of '_BaseExitStack' object "
- "needs an argument")
- elif 'callback' in kwds:
- callback = kwds.pop('callback')
- self, *args = args
- import warnings
- warnings.warn("Passing 'callback' as keyword argument is deprecated",
- DeprecationWarning, stacklevel=2)
- else:
- raise TypeError('callback expected at least 1 positional argument, '
- 'got %d' % (len(args)-1))
-
_exit_wrapper = self._create_cb_wrapper(callback, *args, **kwds)
# We changed the signature, so using @wraps is not appropriate, but
@@ -453,7 +438,6 @@ def callback(*args, **kwds):
_exit_wrapper.__wrapped__ = callback
self._push_exit_callback(_exit_wrapper)
return callback # Allow use as a decorator
- callback.__text_signature__ = '($self, callback, /, *args, **kwds)'
def _push_cm_exit(self, cm, cm_exit):
"""Helper to correctly register callbacks to __exit__ methods."""
@@ -587,26 +571,11 @@ def push_async_exit(self, exit):
self._push_async_cm_exit(exit, exit_method)
return exit # Allow use as a decorator
- def push_async_callback(*args, **kwds):
+ def push_async_callback(self, callback, /, *args, **kwds):
"""Registers an arbitrary coroutine function and arguments.
Cannot suppress exceptions.
"""
- if len(args) >= 2:
- self, callback, *args = args
- elif not args:
- raise TypeError("descriptor 'push_async_callback' of "
- "'AsyncExitStack' object needs an argument")
- elif 'callback' in kwds:
- callback = kwds.pop('callback')
- self, *args = args
- import warnings
- warnings.warn("Passing 'callback' as keyword argument is deprecated",
- DeprecationWarning, stacklevel=2)
- else:
- raise TypeError('push_async_callback expected at least 1 '
- 'positional argument, got %d' % (len(args)-1))
-
_exit_wrapper = self._create_async_cb_wrapper(callback, *args, **kwds)
# We changed the signature, so using @wraps is not appropriate, but
@@ -614,7 +583,6 @@ def push_async_callback(*args, **kwds):
_exit_wrapper.__wrapped__ = callback
self._push_exit_callback(_exit_wrapper, False)
return callback # Allow use as a decorator
- push_async_callback.__text_signature__ = '($self, callback, /, *args, **kwds)'
async def aclose(self):
"""Immediately unwind the context stack."""
diff --git a/Lib/curses/__init__.py b/Lib/curses/__init__.py
index 24ff3ca93a89..69270bfcd2b2 100644
--- a/Lib/curses/__init__.py
+++ b/Lib/curses/__init__.py
@@ -60,7 +60,7 @@ def start_color():
# raises an exception, wrapper() will restore the terminal to a sane state so
# you can read the resulting traceback.
-def wrapper(*args, **kwds):
+def wrapper(func, /, *args, **kwds):
"""Wrapper function that initializes curses and calls another function,
restoring normal keyboard/screen behavior on error.
The callable object 'func' is then passed the main window 'stdscr'
@@ -68,17 +68,6 @@ def wrapper(*args, **kwds):
wrapper().
"""
- if args:
- func, *args = args
- elif 'func' in kwds:
- func = kwds.pop('func')
- import warnings
- warnings.warn("Passing 'func' as keyword argument is deprecated",
- DeprecationWarning, stacklevel=2)
- else:
- raise TypeError('wrapper expected at least 1 positional argument, '
- 'got %d' % len(args))
-
try:
# Initialize curses
stdscr = initscr()
@@ -110,4 +99,3 @@ def wrapper(*args, **kwds):
echo()
nocbreak()
endwin()
-wrapper.__text_signature__ = '(func, /, *args, **kwds)'
diff --git a/Lib/functools.py b/Lib/functools.py
index 64d120182bb0..9495fbe56eba 100644
--- a/Lib/functools.py
+++ b/Lib/functools.py
@@ -345,23 +345,7 @@ class partialmethod(object):
callables as instance methods.
"""
- 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
- import warnings
- warnings.warn("Passing 'func' as keyword argument is deprecated",
- DeprecationWarning, stacklevel=2)
- else:
- raise TypeError("type 'partialmethod' takes at least one argument, "
- "got %d" % (len(args)-1))
- args = tuple(args)
-
+ def __init__(self, func, /, *args, **keywords):
if not callable(func) and not hasattr(func, "__get__"):
raise TypeError("{!r} is not callable or a descriptor"
.format(func))
@@ -379,7 +363,6 @@ def __init__(*args, **keywords):
self.func = func
self.args = args
self.keywords = keywords
- __init__.__text_signature__ = '($self, func, /, *args, **keywords)'
def __repr__(self):
args = ", ".join(map(repr, self.args))
diff --git a/Lib/multiprocessing/managers.py b/Lib/multiprocessing/managers.py
index 7e1818bb0996..75b5150f821b 100644
--- a/Lib/multiprocessing/managers.py
+++ b/Lib/multiprocessing/managers.py
@@ -360,36 +360,10 @@ def shutdown(self, c):
finally:
self.stop_event.set()
- def create(*args, **kwds):
+ def create(self, c, typeid, /, *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]
@@ -421,7 +395,6 @@ def create(*args, **kwds):
self.incref(c, ident)
return ident, tuple(exposed)
- create.__text_signature__ = '($self, c, typeid, /, *args, **kwds)'
def get_methods(self, c, token):
'''
@@ -1293,26 +1266,15 @@ def __init__(self, *args, **kwargs):
_SharedMemoryTracker(f"shmm_{self.address}_{getpid()}")
util.debug(f"SharedMemoryServer started by pid {getpid()}")
- def create(*args, **kwargs):
+ def create(self, c, typeid, /, *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(*args, **kwargs)
- create.__text_signature__ = '($self, c, typeid, /, *args, **kwargs)'
+ return Server.create(self, c, typeid, *args, **kwargs)
def shutdown(self, c):
"Call unlink() on all tracked shared memory, terminate the Server."
diff --git a/Lib/profile.py b/Lib/profile.py
index 1346297c04a5..aad458dc951f 100755
--- a/Lib/profile.py
+++ b/Lib/profile.py
@@ -425,29 +425,13 @@ def runctx(self, cmd, globals, locals):
return self
# This method is more useful to profile a single function call.
- def runcall(*args, **kw):
- if len(args) >= 2:
- self, func, *args = args
- elif not args:
- raise TypeError("descriptor 'runcall' of 'Profile' object "
- "needs an argument")
- elif 'func' in kw:
- func = kw.pop('func')
- self, *args = args
- import warnings
- warnings.warn("Passing 'func' as keyword argument is deprecated",
- DeprecationWarning, stacklevel=2)
- else:
- raise TypeError('runcall expected at least 1 positional argument, '
- 'got %d' % (len(args)-1))
-
+ def runcall(self, func, /, *args, **kw):
self.set_cmd(repr(func))
sys.setprofile(self.dispatcher)
try:
return func(*args, **kw)
finally:
sys.setprofile(None)
- runcall.__text_signature__ = '($self, func, /, *args, **kw)'
#******************************************************************
diff --git a/Lib/test/test_concurrent_futures.py b/Lib/test/test_concurrent_futures.py
index b27ae7194822..2497c2b57275 100644
--- a/Lib/test/test_concurrent_futures.py
+++ b/Lib/test/test_concurrent_futures.py
@@ -668,9 +668,8 @@ def test_submit_keyword(self):
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(fn=capture, arg=1)
with self.assertRaises(TypeError):
self.executor.submit(arg=1)
diff --git a/Lib/test/test_contextlib.py b/Lib/test/test_contextlib.py
index 188a29d9f9fd..024f91264729 100644
--- a/Lib/test/test_contextlib.py
+++ b/Lib/test/test_contextlib.py
@@ -603,9 +603,9 @@ def _exit(*args, **kwds):
stack.callback(arg=1)
with self.assertRaises(TypeError):
self.exit_stack.callback(arg=2)
- with self.assertWarns(DeprecationWarning):
+ with self.assertRaises(TypeError):
stack.callback(callback=_exit, arg=3)
- self.assertEqual(result, [((), {'arg': 3})])
+ self.assertEqual(result, [])
def test_push(self):
exc_raised = ZeroDivisionError
diff --git a/Lib/test/test_contextlib_async.py b/Lib/test/test_contextlib_async.py
index 492b226a0d54..43fb7fced1bf 100644
--- a/Lib/test/test_contextlib_async.py
+++ b/Lib/test/test_contextlib_async.py
@@ -358,9 +358,9 @@ def setUp(self):
stack.push_async_callback(arg=1)
with self.assertRaises(TypeError):
self.exit_stack.push_async_callback(arg=2)
- with self.assertWarns(DeprecationWarning):
+ with self.assertRaises(TypeError):
stack.push_async_callback(callback=_exit, arg=3)
- self.assertEqual(result, [((), {'arg': 3})])
+ self.assertEqual(result, [])
@_async_test
async def test_async_push(self):
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py
index 8fee1c6afdd4..c300270d49e5 100644
--- a/Lib/test/test_functools.py
+++ b/Lib/test/test_functools.py
@@ -556,11 +556,9 @@ class B(object):
with self.assertRaises(TypeError):
class B:
method = functools.partialmethod()
- with self.assertWarns(DeprecationWarning):
+ with self.assertRaises(TypeError):
class B:
method = functools.partialmethod(func=capture, a=1)
- b = B()
- self.assertEqual(b.method(2, x=3), ((b, 2), {'a': 1, 'x': 3}))
def test_repr(self):
self.assertEqual(repr(vars(self.A)['both']),
diff --git a/Lib/test/test_trace.py b/Lib/test/test_trace.py
index 4bc21eae02ce..912badb409d9 100644
--- a/Lib/test/test_trace.py
+++ b/Lib/test/test_trace.py
@@ -276,9 +276,8 @@ def test_simple_caller(self):
def test_arg_errors(self):
res = self.tracer.runfunc(traced_capturer, 1, 2, self=3, func=4)
self.assertEqual(res, ((1, 2), {'self': 3, 'func': 4}))
- with self.assertWarns(DeprecationWarning):
- res = self.tracer.runfunc(func=traced_capturer, arg=1)
- self.assertEqual(res, ((), {'arg': 1}))
+ with self.assertRaises(TypeError):
+ self.tracer.runfunc(func=traced_capturer, arg=1)
with self.assertRaises(TypeError):
self.tracer.runfunc()
diff --git a/Lib/test/test_userdict.py b/Lib/test/test_userdict.py
index 662c7f641af2..483910aaa462 100644
--- a/Lib/test/test_userdict.py
+++ b/Lib/test/test_userdict.py
@@ -30,8 +30,8 @@ def test_all(self):
self.assertEqual(collections.UserDict(one=1, two=2), d2)
# item sequence constructor
self.assertEqual(collections.UserDict([('one',1), ('two',2)]), d2)
- with self.assertWarnsRegex(DeprecationWarning, "'dict'"):
- self.assertEqual(collections.UserDict(dict=[('one',1), ('two',2)]), d2)
+ self.assertEqual(collections.UserDict(dict=[('one',1), ('two',2)]),
+ {'dict': [('one', 1), ('two', 2)]})
# both together
self.assertEqual(collections.UserDict([('one',1), ('two',2)], two=3, three=5), d3)
@@ -149,9 +149,8 @@ def test_init(self):
[('dict', 42)])
self.assertEqual(list(collections.UserDict({}, dict=None).items()),
[('dict', None)])
- with self.assertWarnsRegex(DeprecationWarning, "'dict'"):
- self.assertEqual(list(collections.UserDict(dict={'a': 42}).items()),
- [('a', 42)])
+ self.assertEqual(list(collections.UserDict(dict={'a': 42}).items()),
+ [('dict', {'a': 42})])
self.assertRaises(TypeError, collections.UserDict, 42)
self.assertRaises(TypeError, collections.UserDict, (), ())
self.assertRaises(TypeError, collections.UserDict.__init__)
diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py
index 6f15c03ac529..ce5bbfccd787 100644
--- a/Lib/test/test_weakref.py
+++ b/Lib/test/test_weakref.py
@@ -1866,20 +1866,10 @@ def fin(*args, **kwargs):
f()
self.assertEqual(res, [((1, 2), {'func': 3, 'obj': 4})])
- res = []
- with self.assertWarns(DeprecationWarning):
- f = weakref.finalize(a, func=fin, arg=1)
- self.assertEqual(f.peek(), (a, fin, (), {'arg': 1}))
- f()
- self.assertEqual(res, [((), {'arg': 1})])
-
- res = []
- with self.assertWarns(DeprecationWarning):
- f = weakref.finalize(obj=a, func=fin, arg=1)
- self.assertEqual(f.peek(), (a, fin, (), {'arg': 1}))
- f()
- self.assertEqual(res, [((), {'arg': 1})])
-
+ with self.assertRaises(TypeError):
+ weakref.finalize(a, func=fin, arg=1)
+ with self.assertRaises(TypeError):
+ weakref.finalize(obj=a, func=fin, arg=1)
self.assertRaises(TypeError, weakref.finalize, a)
self.assertRaises(TypeError, weakref.finalize)
diff --git a/Lib/trace.py b/Lib/trace.py
index 62325d3f238a..681c3f9d05f8 100755
--- a/Lib/trace.py
+++ b/Lib/trace.py
@@ -451,22 +451,7 @@ def runctx(self, cmd, globals=None, locals=None):
sys.settrace(None)
threading.settrace(None)
- def runfunc(*args, **kw):
- if len(args) >= 2:
- self, func, *args = args
- elif not args:
- raise TypeError("descriptor 'runfunc' of 'Trace' object "
- "needs an argument")
- elif 'func' in kw:
- func = kw.pop('func')
- self, *args = args
- import warnings
- warnings.warn("Passing 'func' as keyword argument is deprecated",
- DeprecationWarning, stacklevel=2)
- else:
- raise TypeError('runfunc expected at least 1 positional argument, '
- 'got %d' % (len(args)-1))
-
+ def runfunc(self, func, /, *args, **kw):
result = None
if not self.donothing:
sys.settrace(self.globaltrace)
@@ -476,7 +461,6 @@ def runfunc(*args, **kw):
if not self.donothing:
sys.settrace(None)
return result
- runfunc.__text_signature__ = '($self, func, /, *args, **kw)'
def file_module_function_of(self, frame):
code = frame.f_code
diff --git a/Lib/unittest/case.py b/Lib/unittest/case.py
index b363c6351007..8afb84513590 100644
--- a/Lib/unittest/case.py
+++ b/Lib/unittest/case.py
@@ -463,30 +463,13 @@ def addTypeEqualityFunc(self, typeobj, function):
"""
self._type_equality_funcs[typeobj] = function
- def addCleanup(*args, **kwargs):
+ def addCleanup(self, function, /, *args, **kwargs):
"""Add a function, with arguments, to be called when the test is
completed. Functions added are called on a LIFO basis and are
called after tearDown on test failure or success.
Cleanup items are called even if setUp fails (unlike tearDown)."""
- if len(args) >= 2:
- self, function, *args = args
- elif not args:
- raise TypeError("descriptor 'addCleanup' of 'TestCase' object "
- "needs an argument")
- elif 'function' in kwargs:
- function = kwargs.pop('function')
- self, *args = args
- import warnings
- warnings.warn("Passing 'function' as keyword argument is deprecated",
- DeprecationWarning, stacklevel=2)
- else:
- raise TypeError('addCleanup expected at least 1 positional '
- 'argument, got %d' % (len(args)-1))
- args = tuple(args)
-
self._cleanups.append((function, args, kwargs))
- addCleanup.__text_signature__ = '($self, function, /, *args, **kwargs)'
@classmethod
def addClassCleanup(cls, function, /, *args, **kwargs):
diff --git a/Lib/unittest/test/test_runner.py b/Lib/unittest/test/test_runner.py
index 7d36340741f4..dd9a1b6d9aed 100644
--- a/Lib/unittest/test/test_runner.py
+++ b/Lib/unittest/test/test_runner.py
@@ -592,7 +592,7 @@ def cleanup(*args, **kwargs):
class TestableTest(unittest.TestCase):
def setUp(self2):
self2.addCleanup(cleanup, 1, 2, function=3, self=4)
- with self.assertWarns(DeprecationWarning):
+ with self.assertRaises(TypeError):
self2.addCleanup(function=cleanup, arg='hello')
def testNothing(self):
pass
@@ -603,8 +603,7 @@ def testNothing(self):
unittest.TestCase.addCleanup(self=TestableTest(), function=cleanup)
runTests(TestableTest)
self.assertEqual(cleanups,
- [((), {'arg': 'hello'}),
- ((1, 2), {'function': 3, 'self': 4})])
+ [((1, 2), {'function': 3, 'self': 4})])
def test_with_errors_in_addClassCleanup(self):
ordering = []
diff --git a/Lib/weakref.py b/Lib/weakref.py
index 8d71af653b7e..fa7559bb3dbf 100644
--- a/Lib/weakref.py
+++ b/Lib/weakref.py
@@ -514,33 +514,7 @@ class finalize:
class _Info:
__slots__ = ("weakref", "func", "args", "kwargs", "atexit", "index")
- def __init__(*args, **kwargs):
- if len(args) >= 3:
- self, obj, func, *args = args
- elif not args:
- raise TypeError("descriptor '__init__' of 'finalize' object "
- "needs an argument")
- else:
- if 'func' not in kwargs:
- raise TypeError('finalize expected at least 2 positional '
- 'arguments, got %d' % (len(args)-1))
- func = kwargs.pop('func')
- if len(args) >= 2:
- self, obj, *args = args
- import warnings
- warnings.warn("Passing 'func' as keyword argument is deprecated",
- DeprecationWarning, stacklevel=2)
- else:
- if 'obj' not in kwargs:
- raise TypeError('finalize expected at least 2 positional '
- 'arguments, got %d' % (len(args)-1))
- obj = kwargs.pop('obj')
- self, *args = args
- import warnings
- warnings.warn("Passing 'obj' as keyword argument is deprecated",
- DeprecationWarning, stacklevel=2)
- args = tuple(args)
-
+ def __init__(self, obj, func, /, *args, **kwargs):
if not self._registered_with_atexit:
# We may register the exit function more than once because
# of a thread race, but that is harmless
@@ -556,7 +530,6 @@ def __init__(*args, **kwargs):
info.index = next(self._index_iter)
self._registry[self] = info
finalize._dirty = True
- __init__.__text_signature__ = '($self, obj, func, /, *args, **kwargs)'
def __call__(self, _=None):
"""If alive then mark as dead and return func(*args, **kwargs);
More information about the Python-checkins
mailing list