Match CPython's "argument of type ... is not a container or iterable" wording#7714
Conversation
… wording CPython's PySequence_Contains (Objects/abstract.c::_PySequence_IterSearch) catches the TypeError from PyObject_GetIter when neither __contains__ nor __iter__ is available, and re-raises with membership-test wording. RustPython's PySequence::contains propagated the get_iter error verbatim, so '1 in obj' produced 'X' object is not iterable — a literal but less specific message. Wrap the get_iter call in map_err: when the failure is a TypeError, re-raise with byte-identical CPython wording. Other exception types pass through unchanged. Unmasks test_contains.TestContains.test_common_tests.
|
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)
📝 WalkthroughWalkthrough
Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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_contains.py dependencies: dependent tests: (no tests depend on contains) Legend:
|
thanks for the review ! |
Background
CPython's
PySequence_Contains(Objects/abstract.c::_PySequence_IterSearch) catches theTypeErrorfromPyObject_GetIterwhen neither__contains__nor__iter__is available, and re-raises with membership-test wording:RustPython's
PySequence::containspropagated the get_iter error verbatim, so1 in objproduced'X' object is not iterable— a literal but less specific message.Repro
Fix
Wrap the
get_iter(vm)call insidePySequence::containsinmap_err. When the failure is aTypeError(the "not iterable" case), re-raise with the byte-identical CPython membership-test wording. Other exception types (e.g. propagated from a user__iter__) pass through unchanged.Tests unmasked
test_contains.TestContains.test_common_testsVerification
__contains__(str/tuple/dict/set/list/...): unchanged — they go through theslots().containspath before reaching this site__iter__: unchanged —get_itersucceedstest_contains,test_iter,test_dict,test_set,test_list,test_tuple,test_str,test_bytesSummary by CodeRabbit
Bug Fixes