Loading
Restore list semantics in CaselessList
TL;DR
tango.utils.CaselessList.index()now raisesValueErrorwhen the item is absent, instead ofIndexError, and honours the exclusive upper bound.entries += [...]no longer sets the name toNone.[...] + entriesno longer returns its operands swapped.
Reported in #789.
Key Facts
- All three are departures from the
listinterface the class reimplements, and all three are stated correctly in the class's own docstrings. None had a test. index()had one off-by-one with two symptoms. It started the scan atminindex - 1and incremented before indexing, so the final iteration readself[maxindex]. With the default bound that is one past the end, which is why a missing item raisedIndexErrorand the trailingraise ValueErrorwas unreachable. With an explicit bound it matched the element atmaxindex, althoughs.index(x, i, j)excludes it.__iadd__returningNonemeans the bug destroys data rather than just misbehaving: the list is correctly appended to in place, then the name is rebound toNoneand the result thrown away.- No in-tree caller is affected.
CaselessListis used insideCaselessDict.keys(), which does not touch any of these three methods. The class is exported fromtango.utilsbut is not re-exported fromtangoand is not in the published API docs.
Caveats
- The first commit adds the tests and fails on its own; the second makes them pass.
- Two tests carry
# noqa: RUF005. The concatenation operator is the thing under test, so it must not be rewritten as unpacking. - Builds on !1073 (merged) and targets its branch. Retarget to
developonce that merges.