Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Lib/test/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -4217,7 +4217,6 @@ def test_basic_io(self):
def test_constructor(self):
return super().test_constructor()

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_detach(self):
return super().test_detach()

Expand Down
6 changes: 0 additions & 6 deletions Lib/test/test_tarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,6 @@ class ListTest(ReadTest, unittest.TestCase):
def setUp(self):
self.tar = tarfile.open(self.tarname, mode=self.mode)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_list(self):
tio = io.TextIOWrapper(io.BytesIO(), 'ascii', newline='\n')
with support.swap_attr(sys, 'stdout', tio):
Expand Down Expand Up @@ -297,8 +295,6 @@ def conv(b):
self.assertNotIn(b'link to', out)
self.assertNotIn(b'->', out)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_list_verbose(self):
tio = io.TextIOWrapper(io.BytesIO(), 'ascii', newline='\n')
with support.swap_attr(sys, 'stdout', tio):
Expand All @@ -323,8 +319,6 @@ def test_list_verbose(self):
self.assertIn(b'pax' + (b'/123' * 125) + b'/longlink link to pax' +
(b'/123' * 125) + b'/longname', out)

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_list_members(self):
tio = io.TextIOWrapper(io.BytesIO(), 'ascii', newline='\n')
def members(tar):
Expand Down
4 changes: 0 additions & 4 deletions Lib/test/test_tempfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1187,8 +1187,6 @@ def test_properties(self):
with self.assertRaises(AttributeError):
f.errors

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_text_mode(self):
# Creating a SpooledTemporaryFile with a text mode should produce
# a file object reading and writing (Unicode) text strings.
Expand Down Expand Up @@ -1221,8 +1219,6 @@ def test_text_mode(self):
self.assertEqual(f.encoding, "utf-8")
self.assertEqual(f.errors, "strict")

# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_text_newline_and_encoding(self):
f = tempfile.SpooledTemporaryFile(mode='w+', max_size=10,
newline='', encoding='utf-8',
Expand Down
3 changes: 0 additions & 3 deletions Lib/test/test_xml_etree.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,6 @@ def test_copy(self):
self.serialize_check(e2, '<tag>hello<bar /></tag>')
self.serialize_check(e3, '<tag>hello<foo /></tag>')

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_attrib(self):
# Test attribute handling.

Expand Down Expand Up @@ -1481,7 +1480,6 @@ def check(p, expected, namespaces=None):
{'': 'http://www.w3.org/2001/XMLSchema',
'ns': 'http://www.w3.org/2001/XMLSchema'})

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_processinginstruction(self):
# Test ProcessingInstruction directly

Expand Down Expand Up @@ -2369,7 +2367,6 @@ def test_bug_200709_default_namespace(self):
self.assertEqual(str(cm.exception),
'cannot use non-qualified names with default_namespace option')

@unittest.expectedFailure # TODO: RUSTPYTHON
def test_bug_200709_register_namespace(self):
e = ET.Element("{http://namespace.invalid/does/not/exist/}title")
self.assertEqual(ET.tostring(e),
Expand Down
29 changes: 25 additions & 4 deletions crates/vm/src/stdlib/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2405,6 +2405,14 @@ mod _io {
}
}

#[inline]
fn flush_inner(textio: &mut TextIOData, vm: &VirtualMachine) -> PyResult {
textio.check_closed(vm)?;
textio.telling = textio.seekable;
textio.write_pending(vm)?;
vm.call_method(&textio.buffer, "flush", ())
}

#[pyclass(with(Constructor, Initializer), flags(BASETYPE))]
impl TextIOWrapper {
#[pymethod]
Expand Down Expand Up @@ -2439,6 +2447,22 @@ mod _io {
Ok(())
}

#[pymethod]
fn detach(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyResult {
let mut textio = zelf.lock(vm)?;

// Fail fast if already detached
if vm.is_none(&textio.buffer) {
return Err(vm.new_value_error("underlying buffer has been detached"));
}

flush_inner(&mut textio, vm)?;

let buffer = textio.buffer.clone();
textio.buffer = vm.ctx.none();
Ok(buffer)
}

#[pymethod]
fn seekable(&self, vm: &VirtualMachine) -> PyResult {
let textio = self.lock(vm)?;
Expand Down Expand Up @@ -2873,10 +2897,7 @@ mod _io {
#[pymethod]
fn flush(&self, vm: &VirtualMachine) -> PyResult {
let mut textio = self.lock(vm)?;
textio.check_closed(vm)?;
textio.telling = textio.seekable;
textio.write_pending(vm)?;
vm.call_method(&textio.buffer, "flush", ())
flush_inner(&mut textio, vm)
}

#[pymethod]
Expand Down
Loading