raise TypeError when __iter__ method is None#7092
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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 |
Sorry, something went wrong.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@crates/vm/src/types/slot.rs`:
- Around line 548-551: Replace the AttributeError raised when __iter__ is
missing with a TypeError: in the block that calls vm.get_special_method(&zelf,
identifier!(vm, __iter__)), change the ok_or_else(...) from
vm.new_attribute_error(...) to vm.new_type_error(...) and construct the message
as "'<ClassName>' object is not iterable" using the object's class name (e.g.,
format!("'{}' object is not iterable", zelf.class().name())). Keep the existing
method_is_none() TypeError behavior unchanged.
🧹 Nitpick comments (2)
crates/vm/src/types/slot.rs (2)
545-551: Decorative comment separators violate coding guidelines.Lines 545–547 and 553–556 use blank
//lines as section separators. As per coding guidelines, "Do not add decorative section separators (e.g.// -----------,// ===,/* *** */). Use///doc-comments or short//comments only when they add value."Proposed fix: collapse to single-line comments
- // - // look-up '__iter__' method - // + // Look up __iter__ method let method_ident = identifier!(vm, __iter__); let method = vm .get_special_method(&zelf, method_ident)? .ok_or_else(|| vm.new_attribute_error(method_ident.as_str().to_owned()))?; - // - // setting '__iter__' method to 'None' value is used - // to mark non-iterable objects, raise TypeError - // + // __iter__ = None marks non-iterable objects if method_is_none(&method, vm) {
537-562: Consider consistency with__hash__ = Nonehandling.The
__hash__ = Nonecase (lines 758–783) is handled at slot-update time by storinghash_not_implementedas the slot function. The__iter__ = Nonecase is handled at call time inside the wrapper. Both approaches work, but the inconsistency may confuse future maintainers. If there's no strong reason to differ, consider aligning the pattern (e.g., storing a dedicatediter_not_implementedfunction during slot update, similar tohash_not_implemented).That said, CPython's
slot_tp_iteralso checks at call time, so the current approach is arguably more faithful to CPython.
Sorry, something went wrong.
|
Thanks for the PR! |
Sorry, something went wrong.
I'll look into using this approach for |
Sorry, something went wrong.
Setting special `__iter__` method to `None` is used to mark objects as non-iterable. https://docs.python.org/3/reference/datamodel.html#special-method-names Check if `__iter__` is set to `None` and raise TypeError exception.
e131b7c to
bdcc047
Compare
February 12, 2026 16:34
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [x] lib: cpython/Lib/typing.py dependencies:
dependent tests: (12 tests)
Legend:
|
Sorry, something went wrong.
|
@elmjag can you please resolve the conflicts? I think it can be merged |
Sorry, something went wrong.
Setting special
__iter__method toNoneis used to mark objects as non-iterable.https://docs.python.org/3/reference/datamodel.html#special-method-names
Check if
__iter__is set toNoneand raise TypeError exception.Summary by CodeRabbit