dict: match CPython errors for invalid update sequence elements#8338
dict: match CPython errors for invalid update sequence elements#83382jiyong wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (1)
📝 WalkthroughWalkthroughDict update-sequence processing now centralizes conversion, length validation, and contextual error handling for each element. ChangesDict update sequence handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [x] test: cpython/Lib/test/test_dict.py (TODO: 5) dependencies: dependent tests: (no tests depend on dict) Legend:
|
Assisted-by: Codex:gpt-5.6-Sol
Summary
Match CPython's error reporting when
dict()ordict.update()receives an invalid sequence element.test_update_type_error.Implementation details
Previously,
merge_from_seq2extracted the first two items and only checked whether a third item existed. As a result, it could only raise the generic error:CPython converts each dictionary update element to a sequence before validating its length. This allows it to report both the index of the failing element and its actual length:
This change follows the same approach:
PyListandPyTupleinstances use their underlying slices directly, avoiding an unnecessary allocation.Vecso that their actual length can be determined.TypeError: object is not iterable.TypeErrors raised while converting or iterating an element are preserved and receive the contextual note:PyListis imported to support the exact-list fast path, corresponding to CPython'sPySequence_Fasthandling of exact lists and tuples.Summary by CodeRabbit