Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions Lib/collections/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@
try:
from _collections import defaultdict
except ImportError:
# FIXME: try to implement defaultdict in collections.rs rather than in Python
# I (coolreader18) couldn't figure out some class stuff with __new__ and
# __init__ and __missing__ and subclassing built-in types from Rust, so I went
# with this instead.
# TODO: RUSTPYTHON - implement defaultdict in Rust
from ._defaultdict import defaultdict

heapq = None # Lazily imported
Expand Down
19 changes: 16 additions & 3 deletions Lib/test/test_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def __contains__(self, key):
d = c.new_child(b=20, c=30)
self.assertEqual(d.maps, [{'b': 20, 'c': 30}, {'a': 1, 'b': 2}])

@unittest.expectedFailure # TODO: RUSTPYTHON
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_union_operators(self):
cm1 = ChainMap(dict(a=1, b=2), dict(c=3, d=4))
cm2 = ChainMap(dict(a=10, e=5), dict(b=20, d=4))
Expand Down Expand Up @@ -1957,7 +1957,7 @@ class X(ByteString): pass
# No metaclass conflict
class Z(ByteString, Awaitable): pass

@unittest.expectedFailure # TODO: RUSTPYTHON; Need to implement __buffer__ and __release_buffer__ (https://docs.python.org/3.13/reference/datamodel.html#emulating-buffer-types)
@unittest.expectedFailure # TODO: RUSTPYTHON; Need to implement __buffer__ and __release_buffer__ (https://docs.python.org/3.13/reference/datamodel.html#emulating-buffer-types)
def test_Buffer(self):
for sample in [bytes, bytearray, memoryview]:
self.assertIsInstance(sample(b"x"), Buffer)
Expand Down Expand Up @@ -2029,7 +2029,7 @@ def insert(self, index, value):
self.assertEqual(len(mss), len(mss2))
self.assertEqual(list(mss), list(mss2))

@unittest.expectedFailure # TODO: RUSTPYTHON
@unittest.expectedFailure # TODO: RUSTPYTHON
def test_illegal_patma_flags(self):
with self.assertRaises(TypeError):
class Both(Collection):
Expand Down Expand Up @@ -2121,6 +2121,19 @@ def test_basics(self):
self.assertEqual(c.setdefault('e', 5), 5)
self.assertEqual(c['e'], 5)

def test_update_reentrant_add_clears_counter(self):
c = Counter()
key = object()

class Evil(int):
def __add__(self, other):
c.clear()
return NotImplemented

c[key] = Evil()
c.update([key])
self.assertEqual(c[key], 1)

def test_init(self):
self.assertEqual(list(Counter(self=42).items()), [('self', 42)])
self.assertEqual(list(Counter(iterable=42).items()), [('iterable', 42)])
Expand Down
Loading