Skip to content

Commit 2085bd0

Browse files
bpo-37116: Use PEP 570 syntax for positional-only parameters. (GH-13700)
1 parent 4a68650 commit 2085bd0

34 files changed

+126
-261
lines changed

Doc/library/collections.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,7 @@ variants of :func:`functools.lru_cache`::
11401140
class LRU(OrderedDict):
11411141
'Limit size, evicting the least recently looked-up key when full'
11421142

1143-
def __init__(self, maxsize=128, *args, **kwds):
1143+
def __init__(self, maxsize=128, /, *args, **kwds):
11441144
self.maxsize = maxsize
11451145
super().__init__(*args, **kwds)
11461146

Doc/library/contextlib.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ even further by means of a small helper class::
637637
from contextlib import ExitStack
638638

639639
class Callback(ExitStack):
640-
def __init__(self, callback, *args, **kwds):
640+
def __init__(self, callback, /, *args, **kwds):
641641
super(Callback, self).__init__()
642642
self.callback(callback, *args, **kwds)
643643

Doc/library/email.headerregistry.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ headers.
107107
method if it wishes to set additional attributes beyond those provided by
108108
``BaseHeader`` itself. Such an ``init`` method should look like this::
109109

110-
def init(self, *args, **kw):
110+
def init(self, /, *args, **kw):
111111
self._myattr = kw.pop('myattr')
112112
super().init(*args, **kw)
113113

Doc/library/functools.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ The :mod:`functools` module defines the following functions:
221221
Returning NotImplemented from the underlying comparison function for
222222
unrecognised types is now supported.
223223

224-
.. function:: partial(func, *args, **keywords)
224+
.. function:: partial(func, /, *args, **keywords)
225225

226226
Return a new :ref:`partial object<partial-objects>` which when called
227227
will behave like *func* called with the positional arguments *args*
@@ -230,7 +230,7 @@ The :mod:`functools` module defines the following functions:
230230
supplied, they extend and override *keywords*.
231231
Roughly equivalent to::
232232

233-
def partial(func, *args, **keywords):
233+
def partial(func, /, *args, **keywords):
234234
def newfunc(*fargs, **fkeywords):
235235
newkeywords = {**keywords, **fkeywords}
236236
return func(*args, *fargs, **newkeywords)

Doc/library/inspect.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ Classes and functions
10221022
metatype is in use, cls will be the first element of the tuple.
10231023

10241024

1025-
.. function:: getcallargs(func, *args, **kwds)
1025+
.. function:: getcallargs(func, /, *args, **kwds)
10261026

10271027
Bind the *args* and *kwds* to the argument names of the Python function or
10281028
method *func*, as if it was called with them. For bound methods, bind also the

Doc/library/operator.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ expect a function argument.
339339
[('orange', 1), ('banana', 2), ('apple', 3), ('pear', 5)]
340340

341341

342-
.. function:: methodcaller(name[, args...])
342+
.. function:: methodcaller(name, /, *args, **kwargs)
343343

344344
Return a callable object that calls the method *name* on its operand. If
345345
additional arguments and/or keyword arguments are given, they will be given
@@ -352,7 +352,7 @@ expect a function argument.
352352

353353
Equivalent to::
354354

355-
def methodcaller(name, *args, **kwargs):
355+
def methodcaller(name, /, *args, **kwargs):
356356
def caller(obj):
357357
return getattr(obj, name)(*args, **kwargs)
358358
return caller

Doc/library/string.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ implementation as the built-in :meth:`~str.format` method.
8888

8989
The :class:`Formatter` class has the following public methods:
9090

91-
.. method:: format(format_string, *args, **kwargs)
91+
.. method:: format(format_string, /, *args, **kwargs)
9292

9393
The primary API method. It takes a format string and
9494
an arbitrary set of positional and keyword arguments.
@@ -720,7 +720,7 @@ these rules. The methods of :class:`Template` are:
720720
The constructor takes a single argument which is the template string.
721721

722722

723-
.. method:: substitute(mapping, **kwds)
723+
.. method:: substitute(mapping={}, /, **kwds)
724724

725725
Performs the template substitution, returning a new string. *mapping* is
726726
any dictionary-like object with keys that match the placeholders in the
@@ -729,7 +729,7 @@ these rules. The methods of :class:`Template` are:
729729
and there are duplicates, the placeholders from *kwds* take precedence.
730730

731731

732-
.. method:: safe_substitute(mapping, **kwds)
732+
.. method:: safe_substitute(mapping={}, /, **kwds)
733733

734734
Like :meth:`substitute`, except that if placeholders are missing from
735735
*mapping* and *kwds*, instead of raising a :exc:`KeyError` exception, the

Doc/library/types.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ Additional Utility Classes and Functions
327327
The type is roughly equivalent to the following code::
328328

329329
class SimpleNamespace:
330-
def __init__(self, **kwargs):
330+
def __init__(self, /, **kwargs):
331331
self.__dict__.update(kwargs)
332332

333333
def __repr__(self):

Doc/library/unittest.mock-examples.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ Here's an example implementation:
848848

849849
>>> from copy import deepcopy
850850
>>> class CopyingMock(MagicMock):
851-
... def __call__(self, *args, **kwargs):
851+
... def __call__(self, /, *args, **kwargs):
852852
... args = deepcopy(args)
853853
... kwargs = deepcopy(kwargs)
854854
... return super(CopyingMock, self).__call__(*args, **kwargs)
@@ -1042,7 +1042,7 @@ that it takes arbitrary keyword arguments (``**kwargs``) which are then passed
10421042
onto the mock constructor:
10431043

10441044
>>> class Subclass(MagicMock):
1045-
... def _get_child_mock(self, **kwargs):
1045+
... def _get_child_mock(self, /, **kwargs):
10461046
... return MagicMock(**kwargs)
10471047
...
10481048
>>> mymock = Subclass()

Doc/library/unittest.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,7 +1456,7 @@ Test cases
14561456

14571457
.. versionadded:: 3.1
14581458

1459-
.. classmethod:: addClassCleanup(function, *args, **kwargs)
1459+
.. classmethod:: addClassCleanup(function, /, *args, **kwargs)
14601460

14611461
Add a function to be called after :meth:`tearDownClass` to cleanup
14621462
resources used during the test class. Functions will be called in reverse
@@ -2313,7 +2313,7 @@ To add cleanup code that must be run even in the case of an exception, use
23132313
``addModuleCleanup``:
23142314

23152315

2316-
.. function:: addModuleCleanup(function, *args, **kwargs)
2316+
.. function:: addModuleCleanup(function, /, *args, **kwargs)
23172317

23182318
Add a function to be called after :func:`tearDownModule` to cleanup
23192319
resources used during the test class. Functions will be called in reverse

0 commit comments

Comments
 (0)