FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.9] bpo-37116: Use PEP 570 syntax for positional-only parameters. by serhiy-storchaka · Pull Request #12620 · python/cpython · GitHub

Repository navigation

2 changes: 1 addition & 1 deletion Doc/library/bdb.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion Doc/library/concurrent.futures.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Doc/library/contextlib.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion Doc/library/curses.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/profile.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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)``

Expand Down
2 changes: 1 addition & 1 deletion Doc/library/trace.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/unittest.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Doc/library/weakref.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 1 addition & 17 deletions Lib/bdb.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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():
Expand Down
18 changes: 1 addition & 17 deletions Lib/cProfile.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
18 changes: 1 addition & 17 deletions Lib/collections/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
16 changes: 1 addition & 15 deletions Lib/concurrent/futures/_base.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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).
Expand Down
18 changes: 1 addition & 17 deletions Lib/concurrent/futures/process.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand Down
18 changes: 1 addition & 17 deletions Lib/concurrent/futures/thread.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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):
Expand Down
36 changes: 2 additions & 34 deletions Lib/contextlib.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -426,34 +426,18 @@ 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
# setting __wrapped__ may still help with introspection.
_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."""
Expand Down Expand Up @@ -587,34 +571,18 @@ 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
# setting __wrapped__ may still help with introspection.
_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."""
Expand Down
14 changes: 1 addition & 13 deletions Lib/curses/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,14 @@ 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'
as its first argument, followed by any other arguments passed to
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()
Expand Down Expand Up @@ -110,4 +99,3 @@ def wrapper(*args, **kwds):
echo()
nocbreak()
endwin()
wrapper.__text_signature__ = '(func, /, *args, **kwds)'
Loading

Back | FazBrowse Home | New Git URL