You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
StopIteration.value is stored in the instance dict instead of as a member #8290
StopIteration.value is stored in the instance __dict__ instead of as a member (struct field) like CPython. This makes StopIteration().__dict__ non-empty and causes value to return the wrong result when the dict is cleared.
Same class of issue as SystemExit.code (#8230, fixed in #8282). Other built-in exceptions share it (AttributeError, ImportError, SyntaxError, UnicodeDecodeError); this issue targets StopIteration first.
Wrong value:
e=StopIteration(5)
e.__dict__.clear()
print(e.value)
# CPython 3.14: 5 (value is a member, unaffected by dict)# RustPython: None (value lives in the dict, so it's gone)
Cause:value is a class-level None set via set_attr into the instance dict in slot_init, instead of a struct field. The hot-path helper VirtualMachine::new_stop_iteration (crates/vm/src/vm/vm_new.rs) also allocates a fresh dict per call.
Proposed fix: Move value to a struct field on PyStopIteration (the #[repr(C)] + base-field approach used by PyOSError and now SystemExit in #8282), exposed via #[pygetset]. Since StopIteration is raised on a very hot path, this also removes the per-instance dict allocation.
I'll take this and open a PR, following the same approach as #8282.
Python Documentation or reference to CPython source code
Activity
kangdora commentedon Jul 16, 2026
take