mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Merge pull request #4498 from youknowone/str-join
Fix str.join with str subclass
This commit is contained in:
2
Lib/test/string_tests.py
vendored
2
Lib/test/string_tests.py
vendored
@@ -1427,8 +1427,6 @@ class MixinStrUnicodeUserStringTest:
|
||||
class MixinStrUnicodeTest:
|
||||
# Additional tests that only work with str.
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_bug1001011(self):
|
||||
# Make sure join returns a NEW object for single item sequences
|
||||
# involving a subclass.
|
||||
|
||||
@@ -876,13 +876,24 @@ impl PyStr {
|
||||
}
|
||||
|
||||
#[pymethod]
|
||||
fn join(&self, iterable: ArgIterable<PyStrRef>, vm: &VirtualMachine) -> PyResult<PyStrRef> {
|
||||
fn join(
|
||||
zelf: PyRef<Self>,
|
||||
iterable: ArgIterable<PyStrRef>,
|
||||
vm: &VirtualMachine,
|
||||
) -> PyResult<PyStrRef> {
|
||||
let iter = iterable.iter(vm)?;
|
||||
|
||||
match iter.exactly_one() {
|
||||
Ok(first) => first,
|
||||
Err(iter) => Ok(vm.ctx.new_str(self.as_str().py_join(iter)?)),
|
||||
}
|
||||
let joined = match iter.exactly_one() {
|
||||
Ok(first) => {
|
||||
let first = first?;
|
||||
if first.as_object().class().is(vm.ctx.types.str_type) {
|
||||
return Ok(first);
|
||||
} else {
|
||||
first.as_str().to_owned()
|
||||
}
|
||||
}
|
||||
Err(iter) => zelf.as_str().py_join(iter)?,
|
||||
};
|
||||
Ok(joined.into_pystr_ref(vm))
|
||||
}
|
||||
|
||||
// FIXME: two traversals of str is expensive
|
||||
|
||||
Reference in New Issue
Block a user