diff options
| author | shadchin <[email protected]> | 2024-02-12 07:53:52 +0300 |
|---|---|---|
| committer | Daniil Cherednik <[email protected]> | 2024-02-14 14:26:16 +0000 |
| commit | 31f2a419764a8ba77c2a970cfc80056c6cd06756 (patch) | |
| tree | c1995d239eba8571cefc640f6648e1d5dd4ce9e2 /contrib/tools/python3/src/Lib/collections | |
| parent | fe2ef02b38d9c85d80060963b265a1df9f38c3bb (diff) | |
Update Python from 3.11.8 to 3.12.2
Diffstat (limited to 'contrib/tools/python3/src/Lib/collections')
| -rw-r--r-- | contrib/tools/python3/src/Lib/collections/__init__.py | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/contrib/tools/python3/src/Lib/collections/__init__.py b/contrib/tools/python3/src/Lib/collections/__init__.py index 69398ac1164..8652dc8a4ec 100644 --- a/contrib/tools/python3/src/Lib/collections/__init__.py +++ b/contrib/tools/python3/src/Lib/collections/__init__.py @@ -46,6 +46,11 @@ else: _collections_abc.MutableSequence.register(deque) try: + from _collections import _deque_iterator +except ImportError: + pass + +try: from _collections import defaultdict except ImportError: pass @@ -269,7 +274,7 @@ class OrderedDict(dict): 'od.__repr__() <==> repr(od)' if not self: return '%s()' % (self.__class__.__name__,) - return '%s(%r)' % (self.__class__.__name__, list(self.items())) + return '%s(%r)' % (self.__class__.__name__, dict(self.items())) def __reduce__(self): 'Return state information for pickling' @@ -509,9 +514,12 @@ def namedtuple(typename, field_names, *, rename=False, defaults=None, module=Non # specified a particular module. if module is None: try: - module = _sys._getframe(1).f_globals.get('__name__', '__main__') - except (AttributeError, ValueError): - pass + module = _sys._getframemodulename(1) or '__main__' + except AttributeError: + try: + module = _sys._getframe(1).f_globals.get('__name__', '__main__') + except (AttributeError, ValueError): + pass if module is not None: result.__module__ = module @@ -1013,8 +1021,8 @@ 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 + for mapping in map(dict.fromkeys, reversed(self.maps)): + d |= mapping # reuses stored hash values if possible return iter(d) def __contains__(self, key): @@ -1134,10 +1142,17 @@ class UserDict(_collections_abc.MutableMapping): def __iter__(self): return iter(self.data) - # Modify __contains__ to work correctly when __missing__ is present + # Modify __contains__ and get() to work like dict + # does when __missing__ is present. def __contains__(self, key): return key in self.data + def get(self, key, default=None): + if key in self: + return self[key] + return default + + # Now, add the methods in dicts but not in MutableMapping def __repr__(self): return repr(self.data) |
