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
str() discards str subclass type returned by __repr__ #7450
str() on an object whose __repr__ returns a str subclass instance incorrectly returns a plain str, discarding the subclass type. CPython preserves the subclass type as-is. This is a CPython compatibility issue.
Root Cause
PyStr::py_new calls input.str(vm) which correctly resolves to the __repr__ return value (a str subclass instance), but then extracts only the raw string data via Self::from(s.as_wtf8().to_owned()) and creates a new plain PyStr, discarding the subclass type.
// Key branch: only convert when type is a str subclassif (unicode!=NULL&&type!=&PyUnicode_Type) {
Py_SETREF(unicode, unicode_subtype_new(type, unicode));
}
returnunicode; // when type is exactly str → return PyObject_Str result as-is
When type == &PyUnicode_Type (plain str() call), unicode_new_impl returns the PyObject_Str result without conversion, preserving the subclass type.
Activity
Preserve str subclass type returned by __str__ / __repr__ (#7701)
Preserve str subclass type returned by __str__ / __repr__ (#7701)