diff options
| author | darkryder <sambhav13085@iiitd.ac.in> | 2015-07-09 23:30:36 +0530 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-07-09 21:20:52 -0400 |
| commit | f675afa13ce89ea25a9798b2f7a57b091bb83dfa (patch) | |
| tree | 808eb3e261cf5abd798d2b07cf11aef0595ad2cb | |
| parent | 11e6bf9bdfaecd5325686599af5b21b5b945e61c (diff) | |
Fixed #25093 -- Added utils.datastructures.OrderedSet.__len__()
| -rw-r--r-- | django/utils/datastructures.py | 3 | ||||
| -rw-r--r-- | tests/utils_tests/test_datastructures.py | 8 |
2 files changed, 11 insertions, 0 deletions
diff --git a/django/utils/datastructures.py b/django/utils/datastructures.py index 6c60675d38..76f7459032 100644 --- a/django/utils/datastructures.py +++ b/django/utils/datastructures.py @@ -37,6 +37,9 @@ class OrderedSet(object): def __nonzero__(self): # Python 2 compatibility return type(self).__bool__(self) + def __len__(self): + return len(self.dict) + class MultiValueDictKeyError(KeyError): pass diff --git a/tests/utils_tests/test_datastructures.py b/tests/utils_tests/test_datastructures.py index c0ed3435eb..99f7a1d05f 100644 --- a/tests/utils_tests/test_datastructures.py +++ b/tests/utils_tests/test_datastructures.py @@ -21,6 +21,14 @@ class OrderedSetTests(SimpleTestCase): s.add(1) self.assertTrue(s) + def test_len(self): + s = OrderedSet() + self.assertEqual(len(s), 0) + s.add(1) + s.add(2) + s.add(2) + self.assertEqual(len(s), 2) + class MultiValueDictTests(SimpleTestCase): |
