Skip to content

Preserve SortedDict invariants when update input raises - #255

Open
vitalivo wants to merge 1 commit into
grantjenks:masterfrom
vitalivo:fix/update-iterator-errors
Open

Preserve SortedDict invariants when update input raises#255
vitalivo wants to merge 1 commit into
grantjenks:masterfrom
vitalivo:fix/update-iterator-errors

Conversation

@vitalivo

Copy link
Copy Markdown

This replaces #254, which was accidentally closed and its source fork deleted. The implementation is unchanged; the original discussion and reviews remain linked there.


Calling update() on an empty SortedDict with a malformed pair or an iterator that raises can leave keys in the underlying dictionary but not in its sorted index. After catching the original exception, len(d) disagrees with iteration and _check() fails.

Materialize iterable input before taking the empty-dictionary fast path, as the nonempty path already does. The direct-dict optimization remains. Tests cover malformed pairs with and without a key function, a failing generator, and nonempty controls; three cases fail on the base revision.

Validation: all 372 tests, doctests, and stress tests pass on Python 3.12. Ruff passes for the changed library file. Repository-wide Ruff reports five existing B905 diagnostics in untouched sortedlist.py; formatting reports an existing adjacent string literal at sorteddict.py:194. No new lint or formatting issues were introduced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant