Feature
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)
Also observable:
type(StopIteration.value) # CPython: member_descriptor RustPython: NoneType
vars(StopIteration(5)) # CPython: {} RustPython: {'value': 5}
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
https://docs.python.org/3/library/exceptions.html#StopIteration
value is defined as a PyMemberDef (a struct member, not an instance-dict entry) in CPython's Objects/exceptions.c.
Reproduction verified against CPython 3.14.6 and RustPython locally. Issue drafted with AI assistance (Claude), reviewed and edited by me.
Feature
StopIteration.valueis stored in the instance__dict__instead of as a member (struct field) like CPython. This makesStopIteration().__dict__non-empty and causesvalueto 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 targetsStopIterationfirst.Wrong value:
Also observable:
Cause:
valueis a class-levelNoneset viaset_attrinto the instance dict inslot_init, instead of a struct field. The hot-path helperVirtualMachine::new_stop_iteration(crates/vm/src/vm/vm_new.rs) also allocates a fresh dict per call.Proposed fix: Move
valueto a struct field onPyStopIteration(the#[repr(C)]+ base-field approach used byPyOSErrorand nowSystemExitin #8282), exposed via#[pygetset]. SinceStopIterationis 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
https://docs.python.org/3/library/exceptions.html#StopIteration
valueis defined as aPyMemberDef(a struct member, not an instance-dict entry) in CPython'sObjects/exceptions.c.Reproduction verified against CPython 3.14.6 and RustPython locally. Issue drafted with AI assistance (Claude), reviewed and edited by me.