Turn deprecation warnings added in 3.8 into TypeError.
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.
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
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.
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.
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,
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)``
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.
: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
.. 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
# 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
self.quitting = True
sys.settrace(None)
return res
- runcall.__text_signature__ = '($self, func, /, *args, **kwds)'
def set_trace():
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()
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):
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
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).
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)
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):
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)
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):
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
_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."""
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
_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."""
# 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'
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()
echo()
nocbreak()
endwin()
-wrapper.__text_signature__ = '(func, /, *args, **kwds)'
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))
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))
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]
self.incref(c, ident)
return ident, tuple(exposed)
- create.__text_signature__ = '($self, c, typeid, /, *args, **kwds)'
def get_methods(self, c, token):
'''
_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."
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)'
#******************************************************************
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)
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
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):
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']),
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()
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)
[('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__)
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)
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)
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
"""
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):
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
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 = []
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
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);