Skip to content

Commit ec39a61

Browse files
committed
fixup: Formatting fixes, simplify test
1 parent 4f455f4 commit ec39a61

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

Lib/test/test_io/test_textio.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,19 +1568,19 @@ def test_reentrant_detach_during_flush(self):
15681568
# gh-143008: Reentrant detach() during flush should raise RuntimeError
15691569
# instead of crashing.
15701570
wrapper = None
1571-
wrapper_ref = None
1571+
wrapper_ref = lambda: None
15721572

15731573
class EvilBuffer(self.BufferedRandom):
15741574
detach_on_write = False
15751575

15761576
def flush(self):
1577-
wrapper = wrapper_ref() if wrapper_ref is not None else None
1577+
wrapper = wrapper_ref()
15781578
if wrapper is not None and not self.detach_on_write:
15791579
wrapper.detach()
15801580
return super().flush()
15811581

15821582
def write(self, b):
1583-
wrapper = wrapper_ref() if wrapper_ref is not None else None
1583+
wrapper = wrapper_ref()
15841584
if wrapper is not None and self.detach_on_write:
15851585
wrapper.detach()
15861586
return len(b)
@@ -1598,10 +1598,9 @@ def write(self, b):
15981598
with self.subTest(name), set_recursion_limit(100):
15991599
wrapper = self.TextIOWrapper(EvilBuffer(self.MockRawIO()), encoding='utf-8')
16001600
wrapper_ref = weakref.ref(wrapper)
1601-
# These used to crash; now either return detached or keep
1602-
# running until out of stack.
1603-
self.assertRaises((RecursionError, RuntimeError), method)
1604-
wrapper_ref = None
1601+
# Used to crash; now will run out of stack.
1602+
self.assertRaises(RecursionError, method)
1603+
wrapper_ref = lambda: None
16051604
del wrapper
16061605

16071606
with self.subTest('read via writeflush'):
@@ -1610,7 +1609,7 @@ def write(self, b):
16101609
wrapper_ref = weakref.ref(wrapper)
16111610
wrapper.write('x')
16121611
self.assertRaisesRegex(ValueError, "detached", wrapper.read)
1613-
wrapper_ref = None
1612+
wrapper_ref = lambda: None
16141613
del wrapper
16151614

16161615

Modules/_io/textio.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ _textiowrapper_fix_encoder_state(textio *self)
10521052
self->encoding_start_of_stream = 1;
10531053

10541054
PyObject *cookieObj = _textiowrapper_buffer_callmethod_noargs(
1055-
self, &_Py_ID(tell));
1055+
self, &_Py_ID(tell));
10561056
if (cookieObj == NULL) {
10571057
return -1;
10581058
}
@@ -1970,8 +1970,8 @@ textiowrapper_read_chunk(textio *self, Py_ssize_t size_hint)
19701970
goto fail;
19711971

19721972
input_chunk = _textiowrapper_buffer_callmethod_onearg(self,
1973-
(self->has_read1 ? &_Py_ID(read1): &_Py_ID(read)),
1974-
chunk_size);
1973+
(self->has_read1 ? &_Py_ID(read1): &_Py_ID(read)),
1974+
chunk_size);
19751975
Py_DECREF(chunk_size);
19761976
if (input_chunk == NULL)
19771977
goto fail;
@@ -2056,7 +2056,7 @@ _io_TextIOWrapper_read_impl(textio *self, Py_ssize_t n)
20562056
if (n < 0) {
20572057
/* Read everything */
20582058
PyObject *bytes = _textiowrapper_buffer_callmethod_noargs(self,
2059-
&_Py_ID(read));
2059+
&_Py_ID(read));
20602060
PyObject *decoded;
20612061
if (bytes == NULL)
20622062
goto fail;
@@ -2727,7 +2727,7 @@ _io_TextIOWrapper_seek_impl(textio *self, PyObject *cookieObj, int whence)
27272727
goto fail;
27282728
}
27292729
PyObject *input_chunk = _textiowrapper_buffer_callmethod_onearg(self,
2730-
&_Py_ID(read), bytes_to_feed);
2730+
&_Py_ID(read), bytes_to_feed);
27312731
Py_DECREF(bytes_to_feed);
27322732

27332733
PyObject *decoded;
@@ -3219,7 +3219,7 @@ _io_TextIOWrapper_close_impl(textio *self)
32193219
PyObject *exc = NULL;
32203220
if (self->finalizing) {
32213221
res = _textiowrapper_buffer_callmethod_onearg(self,
3222-
&_Py_ID(_dealloc_warn), (PyObject *)self);
3222+
&_Py_ID(_dealloc_warn), (PyObject *)self);
32233223
if (res) {
32243224
Py_DECREF(res);
32253225
}

0 commit comments

Comments
 (0)