Skip to content

Support non-sliceable containers in uniqueness assertions#165

Open
jeet-dekivadia wants to merge 1 commit into
twosigma:mainfrom
jeet-dekivadia:support-nonsliceable-unique-containers
Open

Support non-sliceable containers in uniqueness assertions#165
jeet-dekivadia wants to merge 1 commit into
twosigma:mainfrom
jeet-dekivadia:support-nonsliceable-unique-containers

Conversation

@jeet-dekivadia

@jeet-dekivadia jeet-dekivadia commented May 30, 2026

Copy link
Copy Markdown

Purpose

Allow assertUnique and assertNotUnique to handle iterable containers that do not support slice indexing.

Fixes #74.

Approach

Replace slice-based duplicate detection with a shared iterator-based helper. The helper keeps a list of previously seen elements, preserving support for unhashable values while also supporting containers such as collections.deque.

Tests for New Behavior

  • add regression coverage for unique and duplicate deque values with both assertions
  • git diff --check
  • python3 -m py_compile marbles/mixins/marbles/mixins/mixins.py marbles/mixins/tests/test_mixins.py
  • python3 -m unittest tests.test_mixins.TestUniqueMixins

Checklist

  • Signed and returned a copy of the CLA
  • Added tests for any new features or behaviors
  • Ran nox -s flake8 to make sure code style is consistent
  • Built and reviewed the docs
  • Added a note to the changelog

Learning

The previous implementation intentionally avoided set(container) so unhashable elements would work, but slice indexing narrowed support to sequence-like containers. A seen list keeps the original equality semantics without that indexing requirement.

Remote Linux validation

  • git diff --check
  • python -m compileall -q marbles/mixins
  • python -m unittest tests.test_mixins.TestUniqueMixins -v

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.

assertUnique might break for collections that are not integer-indexable

1 participant