cpython: f2cfa8a348dd (original) (raw)

--- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -812,7 +812,7 @@ class _BufferedIOMixin(BufferedIOBase): clsname = self.class.qualname try: name = self.name

@@ -1640,13 +1640,13 @@ class TextIOWrapper(TextIOBase): self.class.qualname) try: name = self.name

--- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -697,6 +697,8 @@ class CommonBufferedTests: self.assertIs(buf.detach(), raw) self.assertRaises(ValueError, buf.detach)

+ def test_fileno(self): rawio = self.MockRawIO() bufio = self.tp(rawio) @@ -2087,6 +2089,12 @@ class TextIOWrapperTest(unittest.TestCas self.assertEqual(r.getvalue(), b"howdy") self.assertRaises(ValueError, t.detach)

+ def test_repr(self): raw = self.BytesIO("hello".encode("utf-8")) b = self.BufferedReader(raw) @@ -2104,6 +2112,9 @@ class TextIOWrapperTest(unittest.TestCas self.assertEqual(repr(t), "<%s.TextIOWrapper name=b'dummy' mode='r' encoding='utf-8'>" % modname)

+ def test_line_buffering(self): r = self.BytesIO() b = self.BufferedWriter(r, 1000) @@ -2904,6 +2915,9 @@ class CTextIOWrapperTest(TextIOWrapperTe self.assertRaises(ValueError, t.init, b, newline='xyzzy') self.assertRaises(ValueError, t.read)

+ def test_garbage_collection(self): # C TextIOWrapper objects are collected, and collecting them flushes # all data to disk.

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -196,6 +196,9 @@ Core and Builtins Library ------- +- Issue #23093: In the io, module allow more operations to work on detached

--- a/Modules/_io/bufferedio.c +++ b/Modules/_io/bufferedio.c @@ -1404,7 +1404,7 @@ buffered_repr(buffered *self) nameobj = _PyObject_GetAttrId((PyObject *) self, &PyId_name); if (nameobj == NULL) {

--- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -1219,25 +1219,27 @@ textiowrapper_closed_get(textio *self, v #define CHECK_INITIALIZED(self) [](#l5.5) if (self->ok <= 0) { [](#l5.6)

+ +#define CHECK_ATTACHED_INT(self) [](#l5.28) if (self->ok <= 0) { [](#l5.29)

@@ -1254,7 +1256,6 @@ textiowrapper_detach(textio *self) buffer = self->buffer; self->buffer = NULL; self->detached = 1;

@@ -1299,7 +1300,7 @@ textiowrapper_write(textio *self, PyObje int haslf = 0; int needflush = 0, text_needflush = 0;

if (!PyArg_ParseTuple(args, "U:write", &text)) { return NULL; @@ -1562,7 +1563,7 @@ textiowrapper_read(textio *self, PyObjec Py_ssize_t n = -1; PyObject *result = NULL, *chunks = NULL;

if (!PyArg_ParseTuple(args, "|O&:read", &_PyIO_ConvertSsize_t, &n)) return NULL; @@ -1937,7 +1938,7 @@ textiowrapper_readline(textio *self, PyO { Py_ssize_t limit = -1;

if (!PyArg_ParseTuple(args, "O|i:seek", &cookieObj, &whence)) return NULL; @@ -2255,7 +2256,7 @@ textiowrapper_tell(textio *self, PyObjec Py_ssize_t dec_buffer_len; int dec_flags;

+ nameobj = _PyObject_GetAttrId((PyObject *) self, &PyId_name); if (nameobj == NULL) {

@@ -2499,7 +2501,7 @@ textiowrapper_repr(textio *self) } modeobj = _PyObject_GetAttrId((PyObject *) self, &PyId_mode); if (modeobj == NULL) {

@@ -2528,35 +2530,35 @@ error: static PyObject * textiowrapper_fileno(textio *self, PyObject *args) {

static PyObject * textiowrapper_seekable(textio *self, PyObject *args) {

static PyObject * textiowrapper_readable(textio *self, PyObject *args) {

static PyObject * textiowrapper_writable(textio *self, PyObject *args) {

static PyObject * textiowrapper_isatty(textio *self, PyObject *args) {

@@ -2571,7 +2573,7 @@ textiowrapper_getstate(textio *self, PyO static PyObject * textiowrapper_flush(textio *self, PyObject *args) {

res = textiowrapper_closed_get(self, NULL); if (res == NULL) @@ -2626,7 +2628,7 @@ textiowrapper_iternext(textio *self) { PyObject *line;

self->telling = 0; if (Py_TYPE(self) == &PyTextIOWrapper_Type) { @@ -2662,14 +2664,14 @@ textiowrapper_iternext(textio *self) static PyObject * textiowrapper_name_get(textio *self, void *context) {

static PyObject * textiowrapper_closed_get(textio *self, void *context) {

@@ -2677,7 +2679,7 @@ static PyObject * textiowrapper_newlines_get(textio *self, void *context) { PyObject *res;

@@ -2711,7 +2713,7 @@ static int textiowrapper_chunk_size_set(textio *self, PyObject *arg, void *context) { Py_ssize_t n;