Skip to content

fix: complete Collation comparison logic for total ordering#28

Open
dtsong wants to merge 3 commits intomasterfrom
fix/collation-comparison-logic
Open

fix: complete Collation comparison logic for total ordering#28
dtsong wants to merge 3 commits intomasterfrom
fix/collation-comparison-logic

Conversation

@dtsong
Copy link
Owner

@dtsong dtsong commented Mar 13, 2026

Summary

  • Fix __eq__ in Collation to compare languages for ordinal collations (e.g., Albanian_BIN != Latin_BIN in MS SQL) and include absorbs_damage in equality checks for consistency with ordering
  • Fix __gt__ to use deterministic tuple comparison on (language, country, case_sensitive, accent_sensitive, lower_first) instead of returning False for all non-trivial cases, establishing total ordering
  • Add 33 unit tests covering equality, ordering, total ordering properties (reflexivity, antisymmetry, transitivity, no incomparable pairs), and derived operators

Closes #8

Test plan

  • uv run pytest tests/test_collation.py -v — all 33 tests pass
  • make test-unit — no regressions in existing unit tests
  • uv run ruff check . — no lint issues
  • uv run ruff format --check . — formatting clean

🤖 Generated with Claude Code

Fix __eq__ to compare languages for ordinal collations and include
absorbs_damage in equality. Fix __gt__ to use deterministic tuple
comparison instead of returning False for all non-trivial cases.
Add comprehensive test suite with 33 tests covering equality,
ordering, total ordering properties, and derived operators.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3d5b7c8058

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +57 to +58
if self.ordinal != other.ordinal:
return False

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Include ordinal state in comparison ordering

__eq__ now marks ordinal=None and ordinal=False as different, but __gt__ still cannot order that pair when the other fields match, so both a > b and b > a are False; with the current __lt__ definition this makes both a < b and b < a true (e.g., Collation(ordinal=None) vs Collation(ordinal=False)), which breaks antisymmetry and makes sort/max behavior order-dependent when a dialect leaves ordinal unset.

Useful? React with 👍 / 👎.

dtsong and others added 2 commits March 12, 2026 21:54
…cion

- Replace unsafe_hash=True with custom __hash__ via _comparison_key()
  to fix __eq__/__hash__ contract violation (equal objects now always
  have equal hashes)
- Remove country/language None-tolerance from __eq__ to fix equality
  transitivity violation (A==B, B==C but A!=C)
- Use (0,)/(1,val) sentinel wrapping in _ordering_key() so None sorts
  distinctly from "" and False, fixing __eq__/__gt__ inconsistency
- Distinguish ordinal=None from ordinal=False in both equality and
  ordering
- Fix typos in docstring and field comments
- Expand test suite from 33 to 46 tests: hash consistency, equality
  transitivity, None-vs-False edge cases, all sensitivity tiebreakers

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Fix class docstring: Snowflake is "lesser" (preferred target), not
  "greater" — matches actual absorbs_damage logic
- Clarify __gt__ fallthrough comment: absorbs_damage and ordinal are
  already resolved by that point
- Document _ordering_key divergence from _comparison_key for ordinals

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

Incomplete collation comparison logic

1 participant