🐛 Catch Python-equal numeric duplicate keys under OPT_DUPLICATE_KEYS_ERROR#182
Conversation
|
Warning Review limit reached
Next review available in: 58 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #182 +/- ##
==========================================
- Coverage 92.42% 92.29% -0.13%
==========================================
Files 40 40
Lines 11242 11278 +36
==========================================
+ Hits 10390 10409 +19
- Misses 852 869 +17 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR fixes duplicate-key detection under the opt-in OPT_DUPLICATE_KEYS_ERROR (and OPT_DUPLICATE_KEYS_WARN) mode so that keys which are distinct in YAML but equal as Python dict keys (1/1.0/True, 0/False, integral floats vs ints) are now flagged instead of silently collapsing to the last value once the mapping becomes a dict. Previously detection used merge's type-distinct key_sig, which kept these apart. Default last-wins behavior is unchanged. The change is applied consistently across the fast decoder and the round-trip/annotated AST composer, matching ruamel's behavior.
Changes:
- Add a Python-equality key signature that collapses bool/int/bigint/integral-float to a shared
n:signature in the fast decode path (python_dup_key_sig+float_dup_sig) and drop the now-unusedkey_sigimport. - Mirror the same numeric-collapsing logic in the round-trip/annotated AST composer's
key_signature, preserving thes:<<merge-key exemption. - Add tests covering Python-equal numeric duplicate keys (fast + annotated paths) and confirming numerically distinct keys remain allowed.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/decode/mod.rs |
Adds python_dup_key_sig/float_dup_sig and switches check_duplicate_key to use it; removes the unused key_sig import (verified no remaining references). |
src/roundtrip/composer.rs |
Updates key_signature numeric branches to collapse bool/int/bigint/integral-float per Python dict semantics; doc comment updated accordingly. |
tests/features/test_options.py |
Adds parametrized tests for Python-equal numeric duplicate keys and for numerically distinct keys remaining allowed. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ERROR Keys that are distinct in YAML but equal as Python dict keys (1 and 1.0, True and 1, 0 and False) collapse to one entry once the mapping becomes a dict, so one silently overwrote the other even with the strict duplicate-key option set. The detection keyed off a type-distinct signature (merge's key_sig), which kept 1 and 1.0 apart. ruamel raises DuplicateKeyError here. Add a Python-equality signature that collapses a bool/int/bigint/integral-float to the same integer signature, and use it in both duplicate-key paths (the fast decoder and the round-trip composer). Numerically distinct keys (1 vs 2, 1 vs 1.5) and cross-type keys (1 vs "1") are still allowed.
d218947 to
f33fc0c
Compare
Breaking change
None by default (last-wins is unchanged). With
OPT_DUPLICATE_KEYS_ERRORset, a mapping that repeats a key under two Python-equal spellings (1and1.0,Trueand1,0andFalse) now raisesYAMLRocksDuplicateKeyErrorinstead of silently keeping the last value, matching ruamel.Proposed change
Keys distinct in YAML but equal as Python dict keys collapse to one entry once the mapping becomes a
dict, so one silently overwrote the other even with the strict option set. Detection used a type-distinct signature (merge'skey_sig), which kept1and1.0apart.This adds a Python-equality signature that collapses a bool/int/bigint/integral-float to the same integer signature, used in both duplicate-key paths (the fast decoder and the round-trip composer). Numerically distinct keys (
1vs2,1vs1.5) and cross-type keys (1vs"1") are still allowed. The now-unusedkey_sigimport is dropped.Type of change
Additional information
Checklist
uv run pytestpasses locally. A pull request cannot be merged unless CI is green.uv run ruff check .anduv run ruff format --check .pass.cargo fmt --checkandcargo clippy --all-targets -- -D warningspass.