Refs #24121 -- Added __repr__() to OrderedSet.

This commit is contained in:
Nick Pope 2021-03-10 08:29:05 +00:00 committed by GitHub
parent ba9a2b7544
commit afb0eb8bb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 0 deletions

View File

@ -37,6 +37,10 @@ class OrderedSet:
def __len__(self): def __len__(self):
return len(self.dict) return len(self.dict)
def __repr__(self):
data = repr(list(self.dict)) if self.dict else ''
return f'{self.__class__.__qualname__}({data})'
class MultiValueDictKeyError(KeyError): class MultiValueDictKeyError(KeyError):
pass pass

View File

@ -60,6 +60,10 @@ class OrderedSetTests(SimpleTestCase):
s.add(2) s.add(2)
self.assertEqual(len(s), 2) self.assertEqual(len(s), 2)
def test_repr(self):
self.assertEqual(repr(OrderedSet()), 'OrderedSet()')
self.assertEqual(repr(OrderedSet([2, 3, 2, 1])), 'OrderedSet([2, 3, 1])')
class MultiValueDictTests(SimpleTestCase): class MultiValueDictTests(SimpleTestCase):