Skip to content

Commit

Permalink
Bug 1043285 - Fix StrictOrderingOnAppendList.__add__ to not throw whe…
Browse files Browse the repository at this point in the history
…n the list content is not sorted. r=gps
  • Loading branch information
glandium committed Jul 24, 2014
1 parent 29819a4 commit 23da15d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
12 changes: 12 additions & 0 deletions python/mozbuild/mozbuild/test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,18 @@ def test_iadd(self):

self.assertEqual(len(l), 2)

def test_add_after_iadd(self):
l = StrictOrderingOnAppendList(['b'])
l += ['a']
l2 = l + ['c', 'd']
self.assertEqual(len(l), 2)
self.assertEqual(len(l2), 4)
self.assertIsInstance(l2, StrictOrderingOnAppendList)
with self.assertRaises(UnsortedError):
l2 = l + ['d', 'c']

self.assertEqual(len(l), 2)


class TestStrictOrderingOnAppendListWithFlagsFactory(unittest.TestCase):
def test_strict_ordering_on_append_list_with_flags_factory(self):
Expand Down
10 changes: 6 additions & 4 deletions python/mozbuild/mozbuild/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,12 @@ def __add__(self, other):
if not isinstance(other, list):
raise ValueError('Only lists can be appended to lists.')

StrictOrderingOnAppendList.ensure_sorted(other)

# list.__add__ will return a new list. We "cast" it to our type.
return StrictOrderingOnAppendList(list.__add__(self, other))
new_list = StrictOrderingOnAppendList()
# Can't extend with self because it may already be the result of
# several extensions and not be ordered.
list.extend(new_list, self)
new_list.extend(other)
return new_list

def __iadd__(self, other):
if not isinstance(other, list):
Expand Down

0 comments on commit 23da15d

Please sign in to comment.