summaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Lib/collections
diff options
context:
space:
mode:
authorshadchin <[email protected]>2022-02-10 16:44:39 +0300
committerDaniil Cherednik <[email protected]>2022-02-10 16:44:39 +0300
commite9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch)
tree64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/tools/python3/src/Lib/collections
parent2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff)
Restoring authorship annotation for <[email protected]>. Commit 2 of 2.
Diffstat (limited to 'contrib/tools/python3/src/Lib/collections')
-rw-r--r--contrib/tools/python3/src/Lib/collections/__init__.py792
-rw-r--r--contrib/tools/python3/src/Lib/collections/abc.py2
2 files changed, 397 insertions, 397 deletions
diff --git a/contrib/tools/python3/src/Lib/collections/__init__.py b/contrib/tools/python3/src/Lib/collections/__init__.py
index 8ff13906571..5bdd3b3516d 100644
--- a/contrib/tools/python3/src/Lib/collections/__init__.py
+++ b/contrib/tools/python3/src/Lib/collections/__init__.py
@@ -14,29 +14,29 @@ list, set, and tuple.
'''
-__all__ = [
- 'ChainMap',
- 'Counter',
- 'OrderedDict',
- 'UserDict',
- 'UserList',
- 'UserString',
- 'defaultdict',
- 'deque',
- 'namedtuple',
-]
+__all__ = [
+ 'ChainMap',
+ 'Counter',
+ 'OrderedDict',
+ 'UserDict',
+ 'UserList',
+ 'UserString',
+ 'defaultdict',
+ 'deque',
+ 'namedtuple',
+]
import _collections_abc
-import heapq as _heapq
-import sys as _sys
-
-from itertools import chain as _chain
-from itertools import repeat as _repeat
-from itertools import starmap as _starmap
+import heapq as _heapq
+import sys as _sys
+
+from itertools import chain as _chain
+from itertools import repeat as _repeat
+from itertools import starmap as _starmap
from keyword import iskeyword as _iskeyword
-from operator import eq as _eq
-from operator import itemgetter as _itemgetter
-from reprlib import recursive_repr as _recursive_repr
+from operator import eq as _eq
+from operator import itemgetter as _itemgetter
+from reprlib import recursive_repr as _recursive_repr
from _weakref import proxy as _proxy
try:
@@ -60,14 +60,14 @@ def __getattr__(name):
obj = getattr(_collections_abc, name)
import warnings
warnings.warn("Using or importing the ABCs from 'collections' instead "
- "of from 'collections.abc' is deprecated since Python 3.3, "
- "and in 3.10 it will stop working",
+ "of from 'collections.abc' is deprecated since Python 3.3, "
+ "and in 3.10 it will stop working",
DeprecationWarning, stacklevel=2)
globals()[name] = obj
return obj
raise AttributeError(f'module {__name__!r} has no attribute {name!r}')
-
+
################################################################################
### OrderedDict
################################################################################
@@ -107,7 +107,7 @@ class OrderedDict(dict):
# Individual links are kept alive by the hard reference in self.__map.
# Those hard references disappear when a key is deleted from an OrderedDict.
- def __init__(self, other=(), /, **kwds):
+ def __init__(self, other=(), /, **kwds):
'''Initialize an ordered dictionary. The signature is the same as
regular dictionaries. Keyword argument order is preserved.
'''
@@ -118,7 +118,7 @@ class OrderedDict(dict):
self.__root = root = _proxy(self.__hardroot)
root.prev = root.next = root
self.__map = {}
- self.__update(other, **kwds)
+ self.__update(other, **kwds)
def __setitem__(self, key, value,
dict_setitem=dict.__setitem__, proxy=_proxy, Link=_Link):
@@ -307,25 +307,25 @@ class OrderedDict(dict):
return dict.__eq__(self, other) and all(map(_eq, self, other))
return dict.__eq__(self, other)
- def __ior__(self, other):
- self.update(other)
- return self
+ def __ior__(self, other):
+ self.update(other)
+ return self
+
+ def __or__(self, other):
+ if not isinstance(other, dict):
+ return NotImplemented
+ new = self.__class__(self)
+ new.update(other)
+ return new
+
+ def __ror__(self, other):
+ if not isinstance(other, dict):
+ return NotImplemented
+ new = self.__class__(other)
+ new.update(self)
+ return new
+
- def __or__(self, other):
- if not isinstance(other, dict):
- return NotImplemented
- new = self.__class__(self)
- new.update(other)
- return new
-
- def __ror__(self, other):
- if not isinstance(other, dict):
- return NotImplemented
- new = self.__class__(other)
- new.update(self)
- return new
-
-
try:
from _collections import OrderedDict
except ImportError:
@@ -337,10 +337,10 @@ except ImportError:
### namedtuple
################################################################################
-try:
- from _collections import _tuplegetter
-except ImportError:
- _tuplegetter = lambda index, doc: property(_itemgetter(index), doc=doc)
+try:
+ from _collections import _tuplegetter
+except ImportError:
+ _tuplegetter = lambda index, doc: property(_itemgetter(index), doc=doc)
def namedtuple(typename, field_names, *, rename=False, defaults=None, module=None):
"""Returns a new subclass of tuple with named fields.
@@ -413,23 +413,23 @@ def namedtuple(typename, field_names, *, rename=False, defaults=None, module=Non
# Variables used in the methods and docstrings
field_names = tuple(map(_sys.intern, field_names))
num_fields = len(field_names)
- arg_list = ', '.join(field_names)
- if num_fields == 1:
- arg_list += ','
+ arg_list = ', '.join(field_names)
+ if num_fields == 1:
+ arg_list += ','
repr_fmt = '(' + ', '.join(f'{name}=%r' for name in field_names) + ')'
tuple_new = tuple.__new__
- _dict, _tuple, _len, _map, _zip = dict, tuple, len, map, zip
+ _dict, _tuple, _len, _map, _zip = dict, tuple, len, map, zip
# Create all the named tuple methods to be added to the class namespace
- namespace = {
- '_tuple_new': tuple_new,
- '__builtins__': {},
- '__name__': f'namedtuple_{typename}',
- }
- code = f'lambda _cls, {arg_list}: _tuple_new(_cls, ({arg_list}))'
- __new__ = eval(code, namespace)
- __new__.__name__ = '__new__'
+ namespace = {
+ '_tuple_new': tuple_new,
+ '__builtins__': {},
+ '__name__': f'namedtuple_{typename}',
+ }
+ code = f'lambda _cls, {arg_list}: _tuple_new(_cls, ({arg_list}))'
+ __new__ = eval(code, namespace)
+ __new__.__name__ = '__new__'
__new__.__doc__ = f'Create new instance of {typename}({arg_list})'
if defaults is not None:
__new__.__defaults__ = defaults
@@ -444,8 +444,8 @@ def namedtuple(typename, field_names, *, rename=False, defaults=None, module=Non
_make.__func__.__doc__ = (f'Make a new {typename} object from a sequence '
'or iterable')
- def _replace(self, /, **kwds):
- result = self._make(_map(kwds.pop, field_names, self))
+ def _replace(self, /, **kwds):
+ result = self._make(_map(kwds.pop, field_names, self))
if kwds:
raise ValueError(f'Got unexpected field names: {list(kwds)!r}')
return result
@@ -458,22 +458,22 @@ def namedtuple(typename, field_names, *, rename=False, defaults=None, module=Non
return self.__class__.__name__ + repr_fmt % self
def _asdict(self):
- 'Return a new dict which maps field names to their values.'
- return _dict(_zip(self._fields, self))
+ 'Return a new dict which maps field names to their values.'
+ return _dict(_zip(self._fields, self))
def __getnewargs__(self):
'Return self as a plain tuple. Used by copy and pickle.'
- return _tuple(self)
+ return _tuple(self)
# Modify function metadata to help with introspection and debugging
- for method in (
- __new__,
- _make.__func__,
- _replace,
- __repr__,
- _asdict,
- __getnewargs__,
- ):
+ for method in (
+ __new__,
+ _make.__func__,
+ _replace,
+ __repr__,
+ _asdict,
+ __getnewargs__,
+ ):
method.__qualname__ = f'{typename}.{method.__name__}'
# Build-up the class namespace dictionary
@@ -482,7 +482,7 @@ def namedtuple(typename, field_names, *, rename=False, defaults=None, module=Non
'__doc__': f'{typename}({arg_list})',
'__slots__': (),
'_fields': field_names,
- '_field_defaults': field_defaults,
+ '_field_defaults': field_defaults,
'__new__': __new__,
'_make': _make,
'_replace': _replace,
@@ -491,8 +491,8 @@ def namedtuple(typename, field_names, *, rename=False, defaults=None, module=Non
'__getnewargs__': __getnewargs__,
}
for index, name in enumerate(field_names):
- doc = _sys.intern(f'Alias for field number {index}')
- class_namespace[name] = _tuplegetter(index, doc)
+ doc = _sys.intern(f'Alias for field number {index}')
+ class_namespace[name] = _tuplegetter(index, doc)
result = type(typename, (tuple,), class_namespace)
@@ -578,7 +578,7 @@ class Counter(dict):
# http://code.activestate.com/recipes/259174/
# Knuth, TAOCP Vol. II section 4.6.3
- def __init__(self, iterable=None, /, **kwds):
+ def __init__(self, iterable=None, /, **kwds):
'''Create a new, empty Counter object. And if given, count elements
from an input iterable. Or, initialize the count from another mapping
of elements to their counts.
@@ -589,8 +589,8 @@ class Counter(dict):
>>> c = Counter(a=4, b=2) # a new counter from keyword args
'''
- super().__init__()
- self.update(iterable, **kwds)
+ super().__init__()
+ self.update(iterable, **kwds)
def __missing__(self, key):
'The count of elements not in the Counter is zero.'
@@ -601,8 +601,8 @@ class Counter(dict):
'''List the n most common elements and their counts from the most
common to the least. If n is None, then list all element counts.
- >>> Counter('abracadabra').most_common(3)
- [('a', 5), ('b', 2), ('r', 2)]
+ >>> Counter('abracadabra').most_common(3)
+ [('a', 5), ('b', 2), ('r', 2)]
'''
# Emulate Bag.sortedByCount from Smalltalk
@@ -636,17 +636,17 @@ class Counter(dict):
@classmethod
def fromkeys(cls, iterable, v=None):
- # There is no equivalent method for counters because the semantics
- # would be ambiguous in cases such as Counter.fromkeys('aaabbc', v=2).
- # Initializing counters to zero values isn't necessary because zero
- # is already the default value for counter lookups. Initializing
- # to one is easily accomplished with Counter(set(iterable)). For
- # more exotic cases, create a dictionary first using a dictionary
- # comprehension or dict.fromkeys().
+ # There is no equivalent method for counters because the semantics
+ # would be ambiguous in cases such as Counter.fromkeys('aaabbc', v=2).
+ # Initializing counters to zero values isn't necessary because zero
+ # is already the default value for counter lookups. Initializing
+ # to one is easily accomplished with Counter(set(iterable)). For
+ # more exotic cases, create a dictionary first using a dictionary
+ # comprehension or dict.fromkeys().
raise NotImplementedError(
'Counter.fromkeys() is undefined. Use Counter(iterable) instead.')
- def update(self, iterable=None, /, **kwds):
+ def update(self, iterable=None, /, **kwds):
'''Like dict.update() but add counts instead of replacing them.
Source can be an iterable, a dictionary, or another Counter instance.
@@ -673,14 +673,14 @@ class Counter(dict):
for elem, count in iterable.items():
self[elem] = count + self_get(elem, 0)
else:
- # fast path when counter is empty
- super().update(iterable)
+ # fast path when counter is empty
+ super().update(iterable)
else:
_count_elements(self, iterable)
if kwds:
self.update(kwds)
- def subtract(self, iterable=None, /, **kwds):
+ def subtract(self, iterable=None, /, **kwds):
'''Like dict.update() but subtracts counts instead of replacing them.
Counts can be reduced below zero. Both the inputs and outputs are
allowed to contain zero and negative counts.
@@ -721,14 +721,14 @@ class Counter(dict):
def __repr__(self):
if not self:
- return f'{self.__class__.__name__}()'
+ return f'{self.__class__.__name__}()'
try:
- # dict() preserves the ordering returned by most_common()
- d = dict(self.most_common())
+ # dict() preserves the ordering returned by most_common()
+ d = dict(self.most_common())
except TypeError:
# handle case where values are not orderable
- d = dict(self)
- return f'{self.__class__.__name__}({d!r})'
+ d = dict(self)
+ return f'{self.__class__.__name__}({d!r})'
# Multiset-style mathematical operations discussed in:
# Knuth TAOCP Volume II section 4.6.3 exercise 19
@@ -738,13 +738,13 @@ class Counter(dict):
#
# To strip negative and zero counts, add-in an empty counter:
# c += Counter()
- #
- # Rich comparison operators for multiset subset and superset tests
- # are deliberately omitted due to semantic conflicts with the
- # existing inherited dict equality method. Subset and superset
- # semantics ignore zero counts and require that p≤q ∧ p≥q → p=q;
- # however, that would not be the case for p=Counter(a=1, b=0)
- # and q=Counter(a=1) where the dictionaries are not equal.
+ #
+ # Rich comparison operators for multiset subset and superset tests
+ # are deliberately omitted due to semantic conflicts with the
+ # existing inherited dict equality method. Subset and superset
+ # semantics ignore zero counts and require that p≤q ∧ p≥q → p=q;
+ # however, that would not be the case for p=Counter(a=1, b=0)
+ # and q=Counter(a=1) where the dictionaries are not equal.
def __add__(self, other):
'''Add counts from two counters.
@@ -949,7 +949,7 @@ class ChainMap(_collections_abc.MutableMapping):
def __iter__(self):
d = {}
for mapping in reversed(self.maps):
- d.update(dict.fromkeys(mapping)) # reuses stored hash values if possible
+ d.update(dict.fromkeys(mapping)) # reuses stored hash values if possible
return iter(d)
def __contains__(self, key):
@@ -960,7 +960,7 @@ class ChainMap(_collections_abc.MutableMapping):
@_recursive_repr()
def __repr__(self):
- return f'{self.__class__.__name__}({", ".join(map(repr, self.maps))})'
+ return f'{self.__class__.__name__}({", ".join(map(repr, self.maps))})'
@classmethod
def fromkeys(cls, iterable, *args):
@@ -993,7 +993,7 @@ class ChainMap(_collections_abc.MutableMapping):
try:
del self.maps[0][key]
except KeyError:
- raise KeyError(f'Key not found in the first mapping: {key!r}')
+ raise KeyError(f'Key not found in the first mapping: {key!r}')
def popitem(self):
'Remove and return an item pair from maps[0]. Raise KeyError is maps[0] is empty.'
@@ -1007,32 +1007,32 @@ class ChainMap(_collections_abc.MutableMapping):
try:
return self.maps[0].pop(key, *args)
except KeyError:
- raise KeyError(f'Key not found in the first mapping: {key!r}')
+ raise KeyError(f'Key not found in the first mapping: {key!r}')
def clear(self):
'Clear maps[0], leaving maps[1:] intact.'
self.maps[0].clear()
- def __ior__(self, other):
- self.maps[0].update(other)
- return self
+ def __ior__(self, other):
+ self.maps[0].update(other)
+ return self
+
+ def __or__(self, other):
+ if not isinstance(other, _collections_abc.Mapping):
+ return NotImplemented
+ m = self.copy()
+ m.maps[0].update(other)
+ return m
+
+ def __ror__(self, other):
+ if not isinstance(other, _collections_abc.Mapping):
+ return NotImplemented
+ m = dict(other)
+ for child in reversed(self.maps):
+ m.update(child)
+ return self.__class__(m)
+
- def __or__(self, other):
- if not isinstance(other, _collections_abc.Mapping):
- return NotImplemented
- m = self.copy()
- m.maps[0].update(other)
- return m
-
- def __ror__(self, other):
- if not isinstance(other, _collections_abc.Mapping):
- return NotImplemented
- m = dict(other)
- for child in reversed(self.maps):
- m.update(child)
- return self.__class__(m)
-
-
################################################################################
### UserDict
################################################################################
@@ -1040,29 +1040,29 @@ class ChainMap(_collections_abc.MutableMapping):
class UserDict(_collections_abc.MutableMapping):
# Start by filling-out the abstract methods
- def __init__(self, dict=None, /, **kwargs):
+ def __init__(self, dict=None, /, **kwargs):
self.data = {}
if dict is not None:
self.update(dict)
- if kwargs:
+ if kwargs:
self.update(kwargs)
-
- def __len__(self):
- return len(self.data)
-
+
+ def __len__(self):
+ return len(self.data)
+
def __getitem__(self, key):
if key in self.data:
return self.data[key]
if hasattr(self.__class__, "__missing__"):
return self.__class__.__missing__(self, key)
raise KeyError(key)
-
- def __setitem__(self, key, item):
- self.data[key] = item
-
- def __delitem__(self, key):
- del self.data[key]
-
+
+ def __setitem__(self, key, item):
+ self.data[key] = item
+
+ def __delitem__(self, key):
+ del self.data[key]
+
def __iter__(self):
return iter(self.data)
@@ -1071,37 +1071,37 @@ class UserDict(_collections_abc.MutableMapping):
return key in self.data
# Now, add the methods in dicts but not in MutableMapping
- def __repr__(self):
- return repr(self.data)
-
- def __or__(self, other):
- if isinstance(other, UserDict):
- return self.__class__(self.data | other.data)
- if isinstance(other, dict):
- return self.__class__(self.data | other)
- return NotImplemented
-
- def __ror__(self, other):
- if isinstance(other, UserDict):
- return self.__class__(other.data | self.data)
- if isinstance(other, dict):
- return self.__class__(other | self.data)
- return NotImplemented
-
- def __ior__(self, other):
- if isinstance(other, UserDict):
- self.data |= other.data
- else:
- self.data |= other
- return self
-
- def __copy__(self):
- inst = self.__class__.__new__(self.__class__)
- inst.__dict__.update(self.__dict__)
- # Create a copy and avoid triggering descriptors
- inst.__dict__["data"] = self.__dict__["data"].copy()
- return inst
-
+ def __repr__(self):
+ return repr(self.data)
+
+ def __or__(self, other):
+ if isinstance(other, UserDict):
+ return self.__class__(self.data | other.data)
+ if isinstance(other, dict):
+ return self.__class__(self.data | other)
+ return NotImplemented
+
+ def __ror__(self, other):
+ if isinstance(other, UserDict):
+ return self.__class__(other.data | self.data)
+ if isinstance(other, dict):
+ return self.__class__(other | self.data)
+ return NotImplemented
+
+ def __ior__(self, other):
+ if isinstance(other, UserDict):
+ self.data |= other.data
+ else:
+ self.data |= other
+ return self
+
+ def __copy__(self):
+ inst = self.__class__.__new__(self.__class__)
+ inst.__dict__.update(self.__dict__)
+ # Create a copy and avoid triggering descriptors
+ inst.__dict__["data"] = self.__dict__["data"].copy()
+ return inst
+
def copy(self):
if self.__class__ is UserDict:
return UserDict(self.data.copy())
@@ -1114,7 +1114,7 @@ class UserDict(_collections_abc.MutableMapping):
self.data = data
c.update(self)
return c
-
+
@classmethod
def fromkeys(cls, iterable, value=None):
d = cls()
@@ -1129,7 +1129,7 @@ class UserDict(_collections_abc.MutableMapping):
class UserList(_collections_abc.MutableSequence):
"""A more or less complete user-defined wrapper around list objects."""
-
+
def __init__(self, initlist=None):
self.data = []
if initlist is not None:
@@ -1140,60 +1140,60 @@ class UserList(_collections_abc.MutableSequence):
self.data[:] = initlist.data[:]
else:
self.data = list(initlist)
-
- def __repr__(self):
- return repr(self.data)
-
- def __lt__(self, other):
- return self.data < self.__cast(other)
-
- def __le__(self, other):
- return self.data <= self.__cast(other)
-
- def __eq__(self, other):
- return self.data == self.__cast(other)
-
- def __gt__(self, other):
- return self.data > self.__cast(other)
-
- def __ge__(self, other):
- return self.data >= self.__cast(other)
-
+
+ def __repr__(self):
+ return repr(self.data)
+
+ def __lt__(self, other):
+ return self.data < self.__cast(other)
+
+ def __le__(self, other):
+ return self.data <= self.__cast(other)
+
+ def __eq__(self, other):
+ return self.data == self.__cast(other)
+
+ def __gt__(self, other):
+ return self.data > self.__cast(other)
+
+ def __ge__(self, other):
+ return self.data >= self.__cast(other)
+
def __cast(self, other):
return other.data if isinstance(other, UserList) else other
-
- def __contains__(self, item):
- return item in self.data
-
- def __len__(self):
- return len(self.data)
-
- def __getitem__(self, i):
- if isinstance(i, slice):
- return self.__class__(self.data[i])
- else:
- return self.data[i]
-
- def __setitem__(self, i, item):
- self.data[i] = item
-
- def __delitem__(self, i):
- del self.data[i]
-
+
+ def __contains__(self, item):
+ return item in self.data
+
+ def __len__(self):
+ return len(self.data)
+
+ def __getitem__(self, i):
+ if isinstance(i, slice):
+ return self.__class__(self.data[i])
+ else:
+ return self.data[i]
+
+ def __setitem__(self, i, item):
+ self.data[i] = item
+
+ def __delitem__(self, i):
+ del self.data[i]
+
def __add__(self, other):
if isinstance(other, UserList):
return self.__class__(self.data + other.data)
elif isinstance(other, type(self.data)):
return self.__class__(self.data + other)
return self.__class__(self.data + list(other))
-
+
def __radd__(self, other):
if isinstance(other, UserList):
return self.__class__(other.data + self.data)
elif isinstance(other, type(self.data)):
return self.__class__(other + self.data)
return self.__class__(list(other) + self.data)
-
+
def __iadd__(self, other):
if isinstance(other, UserList):
self.data += other.data
@@ -1202,53 +1202,53 @@ class UserList(_collections_abc.MutableSequence):
else:
self.data += list(other)
return self
-
+
def __mul__(self, n):
- return self.__class__(self.data * n)
-
+ return self.__class__(self.data * n)
+
__rmul__ = __mul__
-
+
def __imul__(self, n):
self.data *= n
return self
-
- def __copy__(self):
- inst = self.__class__.__new__(self.__class__)
- inst.__dict__.update(self.__dict__)
- # Create a copy and avoid triggering descriptors
- inst.__dict__["data"] = self.__dict__["data"][:]
- return inst
-
- def append(self, item):
- self.data.append(item)
-
- def insert(self, i, item):
- self.data.insert(i, item)
-
- def pop(self, i=-1):
- return self.data.pop(i)
-
- def remove(self, item):
- self.data.remove(item)
-
- def clear(self):
- self.data.clear()
-
- def copy(self):
- return self.__class__(self)
-
- def count(self, item):
- return self.data.count(item)
-
- def index(self, item, *args):
- return self.data.index(item, *args)
-
- def reverse(self):
- self.data.reverse()
-
- def sort(self, /, *args, **kwds):
- self.data.sort(*args, **kwds)
-
+
+ def __copy__(self):
+ inst = self.__class__.__new__(self.__class__)
+ inst.__dict__.update(self.__dict__)
+ # Create a copy and avoid triggering descriptors
+ inst.__dict__["data"] = self.__dict__["data"][:]
+ return inst
+
+ def append(self, item):
+ self.data.append(item)
+
+ def insert(self, i, item):
+ self.data.insert(i, item)
+
+ def pop(self, i=-1):
+ return self.data.pop(i)
+
+ def remove(self, item):
+ self.data.remove(item)
+
+ def clear(self):
+ self.data.clear()
+
+ def copy(self):
+ return self.__class__(self)
+
+ def count(self, item):
+ return self.data.count(item)
+
+ def index(self, item, *args):
+ return self.data.index(item, *args)
+
+ def reverse(self):
+ self.data.reverse()
+
+ def sort(self, /, *args, **kwds):
+ self.data.sort(*args, **kwds)
+
def extend(self, other):
if isinstance(other, UserList):
self.data.extend(other.data)
@@ -1261,7 +1261,7 @@ class UserList(_collections_abc.MutableSequence):
################################################################################
class UserString(_collections_abc.Sequence):
-
+
def __init__(self, seq):
if isinstance(seq, str):
self.data = seq
@@ -1269,25 +1269,25 @@ class UserString(_collections_abc.Sequence):
self.data = seq.data[:]
else:
self.data = str(seq)
-
- def __str__(self):
- return str(self.data)
-
- def __repr__(self):
- return repr(self.data)
-
- def __int__(self):
- return int(self.data)
-
- def __float__(self):
- return float(self.data)
-
- def __complex__(self):
- return complex(self.data)
-
- def __hash__(self):
- return hash(self.data)
-
+
+ def __str__(self):
+ return str(self.data)
+
+ def __repr__(self):
+ return repr(self.data)
+
+ def __int__(self):
+ return int(self.data)
+
+ def __float__(self):
+ return float(self.data)
+
+ def __complex__(self):
+ return complex(self.data)
+
+ def __hash__(self):
+ return hash(self.data)
+
def __getnewargs__(self):
return (self.data[:],)
@@ -1295,22 +1295,22 @@ class UserString(_collections_abc.Sequence):
if isinstance(string, UserString):
return self.data == string.data
return self.data == string
-
+
def __lt__(self, string):
if isinstance(string, UserString):
return self.data < string.data
return self.data < string
-
+
def __le__(self, string):
if isinstance(string, UserString):
return self.data <= string.data
return self.data <= string
-
+
def __gt__(self, string):
if isinstance(string, UserString):
return self.data > string.data
return self.data > string
-
+
def __ge__(self, string):
if isinstance(string, UserString):
return self.data >= string.data
@@ -1321,188 +1321,188 @@ class UserString(_collections_abc.Sequence):
char = char.data
return char in self.data
- def __len__(self):
- return len(self.data)
-
- def __getitem__(self, index):
- return self.__class__(self.data[index])
-
+ def __len__(self):
+ return len(self.data)
+
+ def __getitem__(self, index):
+ return self.__class__(self.data[index])
+
def __add__(self, other):
if isinstance(other, UserString):
return self.__class__(self.data + other.data)
elif isinstance(other, str):
return self.__class__(self.data + other)
return self.__class__(self.data + str(other))
-
+
def __radd__(self, other):
if isinstance(other, str):
return self.__class__(other + self.data)
return self.__class__(str(other) + self.data)
-
+
def __mul__(self, n):
- return self.__class__(self.data * n)
-
+ return self.__class__(self.data * n)
+
__rmul__ = __mul__
-
+
def __mod__(self, args):
return self.__class__(self.data % args)
-
- def __rmod__(self, template):
- return self.__class__(str(template) % self)
-
+
+ def __rmod__(self, template):
+ return self.__class__(str(template) % self)
+
# the following methods are defined in alphabetical order:
- def capitalize(self):
- return self.__class__(self.data.capitalize())
-
+ def capitalize(self):
+ return self.__class__(self.data.capitalize())
+
def casefold(self):
return self.__class__(self.data.casefold())
-
+
def center(self, width, *args):
return self.__class__(self.data.center(width, *args))
-
+
def count(self, sub, start=0, end=_sys.maxsize):
if isinstance(sub, UserString):
sub = sub.data
return self.data.count(sub, start, end)
-
- def removeprefix(self, prefix, /):
- if isinstance(prefix, UserString):
- prefix = prefix.data
- return self.__class__(self.data.removeprefix(prefix))
-
- def removesuffix(self, suffix, /):
- if isinstance(suffix, UserString):
- suffix = suffix.data
- return self.__class__(self.data.removesuffix(suffix))
-
- def encode(self, encoding='utf-8', errors='strict'):
- encoding = 'utf-8' if encoding is None else encoding
- errors = 'strict' if errors is None else errors
- return self.data.encode(encoding, errors)
-
+
+ def removeprefix(self, prefix, /):
+ if isinstance(prefix, UserString):
+ prefix = prefix.data
+ return self.__class__(self.data.removeprefix(prefix))
+
+ def removesuffix(self, suffix, /):
+ if isinstance(suffix, UserString):
+ suffix = suffix.data
+ return self.__class__(self.data.removesuffix(suffix))
+
+ def encode(self, encoding='utf-8', errors='strict'):
+ encoding = 'utf-8' if encoding is None else encoding
+ errors = 'strict' if errors is None else errors
+ return self.data.encode(encoding, errors)
+
def endswith(self, suffix, start=0, end=_sys.maxsize):
return self.data.endswith(suffix, start, end)
-
+
def expandtabs(self, tabsize=8):
return self.__class__(self.data.expandtabs(tabsize))
-
+
def find(self, sub, start=0, end=_sys.maxsize):
if isinstance(sub, UserString):
sub = sub.data
return self.data.find(sub, start, end)
-
- def format(self, /, *args, **kwds):
+
+ def format(self, /, *args, **kwds):
return self.data.format(*args, **kwds)
-
+
def format_map(self, mapping):
return self.data.format_map(mapping)
-
+
def index(self, sub, start=0, end=_sys.maxsize):
return self.data.index(sub, start, end)
-
- def isalpha(self):
- return self.data.isalpha()
-
- def isalnum(self):
- return self.data.isalnum()
-
- def isascii(self):
- return self.data.isascii()
-
- def isdecimal(self):
- return self.data.isdecimal()
-
- def isdigit(self):
- return self.data.isdigit()
-
- def isidentifier(self):
- return self.data.isidentifier()
-
- def islower(self):
- return self.data.islower()
-
- def isnumeric(self):
- return self.data.isnumeric()
-
- def isprintable(self):
- return self.data.isprintable()
-
- def isspace(self):
- return self.data.isspace()
-
- def istitle(self):
- return self.data.istitle()
-
- def isupper(self):
- return self.data.isupper()
-
- def join(self, seq):
- return self.data.join(seq)
-
+
+ def isalpha(self):
+ return self.data.isalpha()
+
+ def isalnum(self):
+ return self.data.isalnum()
+
+ def isascii(self):
+ return self.data.isascii()
+
+ def isdecimal(self):
+ return self.data.isdecimal()
+
+ def isdigit(self):
+ return self.data.isdigit()
+
+ def isidentifier(self):
+ return self.data.isidentifier()
+
+ def islower(self):
+ return self.data.islower()
+
+ def isnumeric(self):
+ return self.data.isnumeric()
+
+ def isprintable(self):
+ return self.data.isprintable()
+
+ def isspace(self):
+ return self.data.isspace()
+
+ def istitle(self):
+ return self.data.istitle()
+
+ def isupper(self):
+ return self.data.isupper()
+
+ def join(self, seq):
+ return self.data.join(seq)
+
def ljust(self, width, *args):
return self.__class__(self.data.ljust(width, *args))
-
- def lower(self):
- return self.__class__(self.data.lower())
-
- def lstrip(self, chars=None):
- return self.__class__(self.data.lstrip(chars))
-
+
+ def lower(self):
+ return self.__class__(self.data.lower())
+
+ def lstrip(self, chars=None):
+ return self.__class__(self.data.lstrip(chars))
+
maketrans = str.maketrans
-
+
def partition(self, sep):
return self.data.partition(sep)
-
+
def replace(self, old, new, maxsplit=-1):
if isinstance(old, UserString):
old = old.data
if isinstance(new, UserString):
new = new.data
return self.__class__(self.data.replace(old, new, maxsplit))
-
+
def rfind(self, sub, start=0, end=_sys.maxsize):
if isinstance(sub, UserString):
sub = sub.data
return self.data.rfind(sub, start, end)
-
+
def rindex(self, sub, start=0, end=_sys.maxsize):
return self.data.rindex(sub, start, end)
-
+
def rjust(self, width, *args):
return self.__class__(self.data.rjust(width, *args))
-
+
def rpartition(self, sep):
return self.data.rpartition(sep)
-
+
def rstrip(self, chars=None):
return self.__class__(self.data.rstrip(chars))
-
+
def split(self, sep=None, maxsplit=-1):
return self.data.split(sep, maxsplit)
-
+
def rsplit(self, sep=None, maxsplit=-1):
return self.data.rsplit(sep, maxsplit)
-
- def splitlines(self, keepends=False):
- return self.data.splitlines(keepends)
-
+
+ def splitlines(self, keepends=False):
+ return self.data.splitlines(keepends)
+
def startswith(self, prefix, start=0, end=_sys.maxsize):
return self.data.startswith(prefix, start, end)
-
- def strip(self, chars=None):
- return self.__class__(self.data.strip(chars))
-
- def swapcase(self):
- return self.__class__(self.data.swapcase())
-
- def title(self):
- return self.__class__(self.data.title())
-
+
+ def strip(self, chars=None):
+ return self.__class__(self.data.strip(chars))
+
+ def swapcase(self):
+ return self.__class__(self.data.swapcase())
+
+ def title(self):
+ return self.__class__(self.data.title())
+
def translate(self, *args):
return self.__class__(self.data.translate(*args))
-
- def upper(self):
- return self.__class__(self.data.upper())
-
- def zfill(self, width):
- return self.__class__(self.data.zfill(width))
+
+ def upper(self):
+ return self.__class__(self.data.upper())
+
+ def zfill(self, width):
+ return self.__class__(self.data.zfill(width))
diff --git a/contrib/tools/python3/src/Lib/collections/abc.py b/contrib/tools/python3/src/Lib/collections/abc.py
index 6a987916c00..86ca8b8a841 100644
--- a/contrib/tools/python3/src/Lib/collections/abc.py
+++ b/contrib/tools/python3/src/Lib/collections/abc.py
@@ -1,3 +1,3 @@
from _collections_abc import *
from _collections_abc import __all__
-from _collections_abc import _CallableGenericAlias
+from _collections_abc import _CallableGenericAlias