mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Updated __init__.py to be inline with CPython 3.11.2
This commit is contained in:
1 parent
a354f7bba1
commit
32aa9933be
2 files changed
+66
-50
No files matched your search
Vendored
+66
-48
@@ -240,11 +240,19 @@ class OrderedDict(dict):
|
||||
is raised.
|
||||
|
||||
'''
|
||||
if key in self:
|
||||
result = self[key]
|
||||
del self[key]
|
||||
marker = self.__marker
|
||||
result = dict.pop(self, key, marker)
|
||||
if result is not marker:
|
||||
# The same as in __delitem__().
|
||||
link = self.__map.pop(key)
|
||||
link_prev = link.prev
|
||||
link_next = link.next
|
||||
link_prev.next = link_next
|
||||
link_next.prev = link_prev
|
||||
link.prev = None
|
||||
link.next = None
|
||||
return result
|
||||
if default is self.__marker:
|
||||
if default is marker:
|
||||
raise KeyError(key)
|
||||
return default
|
||||
|
||||
@@ -267,10 +275,22 @@ class OrderedDict(dict):
|
||||
|
||||
def __reduce__(self):
|
||||
'Return state information for pickling'
|
||||
inst_dict = vars(self).copy()
|
||||
for k in vars(OrderedDict()):
|
||||
inst_dict.pop(k, None)
|
||||
return self.__class__, (), inst_dict or None, None, iter(self.items())
|
||||
state = self.__getstate__()
|
||||
if state:
|
||||
if isinstance(state, tuple):
|
||||
state, slots = state
|
||||
else:
|
||||
slots = {}
|
||||
state = state.copy()
|
||||
slots = slots.copy()
|
||||
for k in vars(OrderedDict()):
|
||||
state.pop(k, None)
|
||||
slots.pop(k, None)
|
||||
if slots:
|
||||
state = state, slots
|
||||
else:
|
||||
state = state or None
|
||||
return self.__class__, (), state, None, iter(self.items())
|
||||
|
||||
def copy(self):
|
||||
'od.copy() -> a shallow copy of od'
|
||||
@@ -613,11 +633,9 @@ class Counter(dict):
|
||||
['A', 'A', 'B', 'B', 'C', 'C']
|
||||
|
||||
# Knuth's example for prime factors of 1836: 2**2 * 3**3 * 17**1
|
||||
>>> import math
|
||||
>>> prime_factors = Counter({2: 2, 3: 3, 17: 1})
|
||||
>>> product = 1
|
||||
>>> for factor in prime_factors.elements(): # loop over factors
|
||||
... product *= factor # and multiply them
|
||||
>>> product
|
||||
>>> math.prod(prime_factors.elements())
|
||||
1836
|
||||
|
||||
Note, if an element's count has been set to zero or is a negative
|
||||
@@ -714,42 +732,6 @@ class Counter(dict):
|
||||
if elem in self:
|
||||
super().__delitem__(elem)
|
||||
|
||||
def __eq__(self, other):
|
||||
'True if all counts agree. Missing counts are treated as zero.'
|
||||
if not isinstance(other, Counter):
|
||||
return NotImplemented
|
||||
return all(self[e] == other[e] for c in (self, other) for e in c)
|
||||
|
||||
def __ne__(self, other):
|
||||
'True if any counts disagree. Missing counts are treated as zero.'
|
||||
if not isinstance(other, Counter):
|
||||
return NotImplemented
|
||||
return not self == other
|
||||
|
||||
def __le__(self, other):
|
||||
'True if all counts in self are a subset of those in other.'
|
||||
if not isinstance(other, Counter):
|
||||
return NotImplemented
|
||||
return all(self[e] <= other[e] for c in (self, other) for e in c)
|
||||
|
||||
def __lt__(self, other):
|
||||
'True if all counts in self are a proper subset of those in other.'
|
||||
if not isinstance(other, Counter):
|
||||
return NotImplemented
|
||||
return self <= other and self != other
|
||||
|
||||
def __ge__(self, other):
|
||||
'True if all counts in self are a superset of those in other.'
|
||||
if not isinstance(other, Counter):
|
||||
return NotImplemented
|
||||
return all(self[e] >= other[e] for c in (self, other) for e in c)
|
||||
|
||||
def __gt__(self, other):
|
||||
'True if all counts in self are a proper superset of those in other.'
|
||||
if not isinstance(other, Counter):
|
||||
return NotImplemented
|
||||
return self >= other and self != other
|
||||
|
||||
def __repr__(self):
|
||||
if not self:
|
||||
return f'{self.__class__.__name__}()'
|
||||
@@ -795,6 +777,42 @@ class Counter(dict):
|
||||
# (cp >= cq) == (sp >= sq)
|
||||
# (cp > cq) == (sp > sq)
|
||||
|
||||
def __eq__(self, other):
|
||||
'True if all counts agree. Missing counts are treated as zero.'
|
||||
if not isinstance(other, Counter):
|
||||
return NotImplemented
|
||||
return all(self[e] == other[e] for c in (self, other) for e in c)
|
||||
|
||||
def __ne__(self, other):
|
||||
'True if any counts disagree. Missing counts are treated as zero.'
|
||||
if not isinstance(other, Counter):
|
||||
return NotImplemented
|
||||
return not self == other
|
||||
|
||||
def __le__(self, other):
|
||||
'True if all counts in self are a subset of those in other.'
|
||||
if not isinstance(other, Counter):
|
||||
return NotImplemented
|
||||
return all(self[e] <= other[e] for c in (self, other) for e in c)
|
||||
|
||||
def __lt__(self, other):
|
||||
'True if all counts in self are a proper subset of those in other.'
|
||||
if not isinstance(other, Counter):
|
||||
return NotImplemented
|
||||
return self <= other and self != other
|
||||
|
||||
def __ge__(self, other):
|
||||
'True if all counts in self are a superset of those in other.'
|
||||
if not isinstance(other, Counter):
|
||||
return NotImplemented
|
||||
return all(self[e] >= other[e] for c in (self, other) for e in c)
|
||||
|
||||
def __gt__(self, other):
|
||||
'True if all counts in self are a proper superset of those in other.'
|
||||
if not isinstance(other, Counter):
|
||||
return NotImplemented
|
||||
return self >= other and self != other
|
||||
|
||||
def __add__(self, other):
|
||||
'''Add counts from two counters.
|
||||
|
||||
|
||||
Vendored
-2
@@ -983,8 +983,6 @@ class SimpleLRUCacheTests:
|
||||
self.assertEqual(c.popitem(last=True), (3, 3))
|
||||
self.assertEqual(c.counts, {'get': 0, 'set': 3, 'del': 0})
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_pop(self):
|
||||
c = self.type2test(3)
|
||||
for i in range(1, 4):
|
||||
|
||||
Reference in new issue
Block a user