Skip to content

Comments

fix: add types.UnionType support to comparator#1617

Open
aseembits93 wants to merge 1 commit intomainfrom
comparator-uniontype
Open

fix: add types.UnionType support to comparator#1617
aseembits93 wants to merge 1 commit intomainfrom
comparator-uniontype

Conversation

@aseembits93
Copy link
Contributor

Summary

  • The comparator did not handle types.UnionType (the type produced by Python 3.10+ X | Y union syntax), causing it to log "Unknown comparator input type" and return False for valid equal unions.
  • Conditionally adds types.UnionType to the equality-checked types tuple (guarded by getattr for Python 3.9 compatibility).
  • Adds 7 tests covering equality, inequality, order independence, multi-arg unions, nested containers, and None comparison.

Test plan

  • All 7 new TestUnionType tests pass
  • Full comparator test suite passes (139 passed, 43 skipped)
  • Ruff linting passes on comparator.py
  • Python 3.9 compatible (conditional inclusion via getattr)

🤖 Generated with Claude Code

The comparator did not recognize `types.UnionType` (Python 3.10+ `X | Y`
syntax), causing it to fall through to "Unknown comparator input type".
Conditionally include it in the equality-checked types tuple.

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

claude bot commented Feb 20, 2026

PR Review Summary

Prek Checks

✅ All checks passed (ruff check, ruff format) — no issues found.

Mypy

✅ No new mypy errors introduced by this PR. All reported errors are pre-existing on main.

Code Review

✅ No critical bugs, security vulnerabilities, or breaking API changes found.

Notes:

  • The _equality_types tuple is rebuilt on every comparator() call due to the runtime getattr + walrus operator pattern. This is functionally correct and the overhead is negligible, but it could be moved to module level for a minor efficiency gain.
  • The getattr(types, "UnionType", None) guard correctly handles Python 3.9 compatibility.
  • Tests are well-structured with appropriate skipif for Python < 3.10.

Test Coverage

File Stmts (PR) Miss (PR) Cover (PR) Cover (main) Delta
codeflash/verification/comparator.py 379 163 57% 56% +1%
tests/test_comparator.py 3315 1354 59% 59% 0%
  • ✅ All new lines in comparator.py (lines 148-169) are covered by tests
  • ✅ All 7 new TestUnionType tests pass (139 passed, 43 skipped total)
  • ✅ No coverage regressions — slight improvement (+1%) on comparator.py

Last updated: 2026-02-20

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