bpo-37116: Use PEP 570 syntax for positional-only parameters. (GH-13700) · python/cpython@2085bd0 (original) (raw)
`@@ -93,24 +93,18 @@ class OrderedDict(dict):
`
93
93
`# Individual links are kept alive by the hard reference in self.__map.
`
94
94
`# Those hard references disappear when a key is deleted from an OrderedDict.
`
95
95
``
96
``
`-
def init(*args, **kwds):
`
``
96
`+
def init(self, other=(), /, **kwds):
`
97
97
`'''Initialize an ordered dictionary. The signature is the same as
`
98
98
` regular dictionaries. Keyword argument order is preserved.
`
99
99
` '''
`
100
``
`-
if not args:
`
101
``
`-
raise TypeError("descriptor 'init' of 'OrderedDict' object "
`
102
``
`-
"needs an argument")
`
103
``
`-
self, *args = args
`
104
``
`-
if len(args) > 1:
`
105
``
`-
raise TypeError('expected at most 1 arguments, got %d' % len(args))
`
106
100
`try:
`
107
101
`self.__root
`
108
102
`except AttributeError:
`
109
103
`self.__hardroot = _Link()
`
110
104
`self.__root = root = _proxy(self.__hardroot)
`
111
105
`root.prev = root.next = root
`
112
106
`self.__map = {}
`
113
``
`-
self.__update(*args, **kwds)
`
``
107
`+
self.__update(other, **kwds)
`
114
108
``
115
109
`def setitem(self, key, value,
`
116
110
`dict_setitem=dict.setitem, proxy=_proxy, Link=_Link):
`
`@@ -413,8 +407,8 @@ def _make(cls, iterable):
`
413
407
`_make.func.doc = (f'Make a new {typename} object from a sequence '
`
414
408
`'or iterable')
`
415
409
``
416
``
`-
def _replace(_self, **kwds):
`
417
``
`-
result = _self._make(_map(kwds.pop, field_names, _self))
`
``
410
`+
def _replace(self, /, **kwds):
`
``
411
`+
result = self._make(_map(kwds.pop, field_names, self))
`
418
412
`if kwds:
`
419
413
`raise ValueError(f'Got unexpected field names: {list(kwds)!r}')
`
420
414
`return result
`
`@@ -543,7 +537,7 @@ class Counter(dict):
`
543
537
`# http://code.activestate.com/recipes/259174/
`
544
538
`# Knuth, TAOCP Vol. II section 4.6.3
`
545
539
``
546
``
`-
def init(*args, **kwds):
`
``
540
`+
def init(self, iterable=None, /, **kwds):
`
547
541
`'''Create a new, empty Counter object. And if given, count elements
`
548
542
` from an input iterable. Or, initialize the count from another mapping
`
549
543
` of elements to their counts.
`
`@@ -554,14 +548,8 @@ def init(*args, **kwds):
`
554
548
` >>> c = Counter(a=4, b=2) # a new counter from keyword args
`
555
549
``
556
550
` '''
`
557
``
`-
if not args:
`
558
``
`-
raise TypeError("descriptor 'init' of 'Counter' object "
`
559
``
`-
"needs an argument")
`
560
``
`-
self, *args = args
`
561
``
`-
if len(args) > 1:
`
562
``
`-
raise TypeError('expected at most 1 arguments, got %d' % len(args))
`
563
551
`super(Counter, self).init()
`
564
``
`-
self.update(*args, **kwds)
`
``
552
`+
self.update(iterable, **kwds)
`
565
553
``
566
554
`def missing(self, key):
`
567
555
`'The count of elements not in the Counter is zero.'
`
`@@ -617,7 +605,7 @@ def fromkeys(cls, iterable, v=None):
`
617
605
`raise NotImplementedError(
`
618
606
`'Counter.fromkeys() is undefined. Use Counter(iterable) instead.')
`
619
607
``
620
``
`-
def update(*args, **kwds):
`
``
608
`+
def update(self, iterable=None, /, **kwds):
`
621
609
`'''Like dict.update() but add counts instead of replacing them.
`
622
610
``
623
611
` Source can be an iterable, a dictionary, or another Counter instance.
`
`@@ -637,13 +625,6 @@ def update(*args, **kwds):
`
637
625
`# contexts. Instead, we implement straight-addition. Both the inputs
`
638
626
`# and outputs are allowed to contain zero and negative counts.
`
639
627
``
640
``
`-
if not args:
`
641
``
`-
raise TypeError("descriptor 'update' of 'Counter' object "
`
642
``
`-
"needs an argument")
`
643
``
`-
self, *args = args
`
644
``
`-
if len(args) > 1:
`
645
``
`-
raise TypeError('expected at most 1 arguments, got %d' % len(args))
`
646
``
`-
iterable = args[0] if args else None
`
647
628
`if iterable is not None:
`
648
629
`if isinstance(iterable, _collections_abc.Mapping):
`
649
630
`if self:
`
`@@ -657,7 +638,7 @@ def update(*args, **kwds):
`
657
638
`if kwds:
`
658
639
`self.update(kwds)
`
659
640
``
660
``
`-
def subtract(*args, **kwds):
`
``
641
`+
def subtract(self, iterable=None, /, **kwds):
`
661
642
`'''Like dict.update() but subtracts counts instead of replacing them.
`
662
643
` Counts can be reduced below zero. Both the inputs and outputs are
`
663
644
` allowed to contain zero and negative counts.
`
`@@ -673,13 +654,6 @@ def subtract(*args, **kwds):
`
673
654
` -1
`
674
655
``
675
656
` '''
`
676
``
`-
if not args:
`
677
``
`-
raise TypeError("descriptor 'subtract' of 'Counter' object "
`
678
``
`-
"needs an argument")
`
679
``
`-
self, *args = args
`
680
``
`-
if len(args) > 1:
`
681
``
`-
raise TypeError('expected at most 1 arguments, got %d' % len(args))
`
682
``
`-
iterable = args[0] if args else None
`
683
657
`if iterable is not None:
`
684
658
`self_get = self.get
`
685
659
`if isinstance(iterable, _collections_abc.Mapping):
`
`@@ -1141,7 +1115,7 @@ def copy(self): return self.class(self)
`
1141
1115
`def count(self, item): return self.data.count(item)
`
1142
1116
`def index(self, item, *args): return self.data.index(item, *args)
`
1143
1117
`def reverse(self): self.data.reverse()
`
1144
``
`-
def sort(self, *args, **kwds): self.data.sort(*args, **kwds)
`
``
1118
`+
def sort(self, /, *args, **kwds): self.data.sort(*args, **kwds)
`
1145
1119
`def extend(self, other):
`
1146
1120
`if isinstance(other, UserList):
`
1147
1121
`self.data.extend(other.data)
`
`@@ -1240,7 +1214,7 @@ def find(self, sub, start=0, end=_sys.maxsize):
`
1240
1214
`if isinstance(sub, UserString):
`
1241
1215
`sub = sub.data
`
1242
1216
`return self.data.find(sub, start, end)
`
1243
``
`-
def format(self, *args, **kwds):
`
``
1217
`+
def format(self, /, *args, **kwds):
`
1244
1218
`return self.data.format(*args, **kwds)
`
1245
1219
`def format_map(self, mapping):
`
1246
1220
`return self.data.format_map(mapping)
`