Skip to content

Commit ce8d3db

Browse files
gh-101819: Adapt _io._BufferedIOBase_Type methods to Argument Clinic (#104355)
Make sure the defining class is passed to all methods, so we can easily fetch module state from them in the future.
1 parent 13ac176 commit ce8d3db

File tree

2 files changed

+236
-44
lines changed

2 files changed

+236
-44
lines changed

Modules/_io/bufferedio.c

+68-39
Original file line numberDiff line numberDiff line change
@@ -115,70 +115,99 @@ bufferediobase_unsupported(_PyIO_State *state, const char *message)
115115
/*[clinic input]
116116
_io._BufferedIOBase.detach
117117
118+
cls: defining_class
119+
/
120+
118121
Disconnect this buffer from its underlying raw stream and return it.
119122
120123
After the raw stream has been detached, the buffer is in an unusable
121124
state.
122125
[clinic start generated code]*/
123126

124127
static PyObject *
125-
_io__BufferedIOBase_detach_impl(PyObject *self)
126-
/*[clinic end generated code: output=754977c8d10ed88c input=822427fb58fe4169]*/
128+
_io__BufferedIOBase_detach_impl(PyObject *self, PyTypeObject *cls)
129+
/*[clinic end generated code: output=b87b135d67cd4448 input=0b61a7b4357c1ea7]*/
127130
{
128131
_PyIO_State *state = IO_STATE();
129132
return bufferediobase_unsupported(state, "detach");
130133
}
131134

132-
PyDoc_STRVAR(bufferediobase_read_doc,
133-
"Read and return up to n bytes.\n"
134-
"\n"
135-
"If the argument is omitted, None, or negative, reads and\n"
136-
"returns all data until EOF.\n"
137-
"\n"
138-
"If the argument is positive, and the underlying raw stream is\n"
139-
"not 'interactive', multiple raw reads may be issued to satisfy\n"
140-
"the byte count (unless EOF is reached first). But for\n"
141-
"interactive raw streams (as well as sockets and pipes), at most\n"
142-
"one raw read will be issued, and a short result does not imply\n"
143-
"that EOF is imminent.\n"
144-
"\n"
145-
"Returns an empty bytes object on EOF.\n"
146-
"\n"
147-
"Returns None if the underlying raw stream was open in non-blocking\n"
148-
"mode and no data is available at the moment.\n");
135+
/*[clinic input]
136+
_io._BufferedIOBase.read
137+
138+
cls: defining_class
139+
/
140+
*args: object
141+
142+
Read and return up to n bytes.
143+
144+
If the argument is omitted, None, or negative, read and
145+
return all data until EOF.
146+
147+
If the argument is positive, and the underlying raw stream is
148+
not 'interactive', multiple raw reads may be issued to satisfy
149+
the byte count (unless EOF is reached first).
150+
However, for interactive raw streams (as well as sockets and pipes),
151+
at most one raw read will be issued, and a short result does not
152+
imply that EOF is imminent.
153+
154+
Return an empty bytes object on EOF.
155+
156+
Return None if the underlying raw stream was open in non-blocking
157+
mode and no data is available at the moment.
158+
[clinic start generated code]*/
149159

150160
static PyObject *
151-
bufferediobase_read(PyObject *self, PyObject *args)
161+
_io__BufferedIOBase_read_impl(PyObject *self, PyTypeObject *cls,
162+
PyObject *args)
163+
/*[clinic end generated code: output=4521b30940fd7b67 input=390205758adc8510]*/
152164
{
153165
_PyIO_State *state = IO_STATE();
154166
return bufferediobase_unsupported(state, "read");
155167
}
156168

157-
PyDoc_STRVAR(bufferediobase_read1_doc,
158-
"Read and return up to n bytes, with at most one read() call\n"
159-
"to the underlying raw stream. A short result does not imply\n"
160-
"that EOF is imminent.\n"
161-
"\n"
162-
"Returns an empty bytes object on EOF.\n");
169+
/*[clinic input]
170+
_io._BufferedIOBase.read1
171+
172+
cls: defining_class
173+
/
174+
*args: object
175+
176+
Read and return up to n bytes, with at most one read() call to the underlying raw stream.
177+
178+
Return an empty bytes object on EOF.
179+
A short result does not imply that EOF is imminent.
180+
[clinic start generated code]*/
163181

164182
static PyObject *
165-
bufferediobase_read1(PyObject *self, PyObject *args)
183+
_io__BufferedIOBase_read1_impl(PyObject *self, PyTypeObject *cls,
184+
PyObject *args)
185+
/*[clinic end generated code: output=636fd241c21e050a input=ef546a1238c5b41c]*/
166186
{
167187
_PyIO_State *state = IO_STATE();
168188
return bufferediobase_unsupported(state, "read1");
169189
}
170190

171-
PyDoc_STRVAR(bufferediobase_write_doc,
172-
"Write the given buffer to the IO stream.\n"
173-
"\n"
174-
"Returns the number of bytes written, which is always the length of b\n"
175-
"in bytes.\n"
176-
"\n"
177-
"Raises BlockingIOError if the buffer is full and the\n"
178-
"underlying raw stream cannot accept more data at the moment.\n");
191+
/*[clinic input]
192+
_io._BufferedIOBase.write
193+
194+
cls: defining_class
195+
/
196+
*args: object
197+
198+
Write the given buffer to the IO stream.
199+
200+
Return the number of bytes written, which is always
201+
the length of b in bytes.
202+
203+
Raise BlockingIOError if the buffer is full and the
204+
underlying raw stream cannot accept more data at the moment.
205+
[clinic start generated code]*/
179206

180207
static PyObject *
181-
bufferediobase_write(PyObject *self, PyObject *args)
208+
_io__BufferedIOBase_write_impl(PyObject *self, PyTypeObject *cls,
209+
PyObject *args)
210+
/*[clinic end generated code: output=d51feea4bcac9892 input=f79b72c4dccb3dc2]*/
182211
{
183212
_PyIO_State *state = IO_STATE();
184213
return bufferediobase_unsupported(state, "write");
@@ -2336,11 +2365,11 @@ _io_BufferedRandom___init___impl(buffered *self, PyObject *raw,
23362365

23372366
static PyMethodDef bufferediobase_methods[] = {
23382367
_IO__BUFFEREDIOBASE_DETACH_METHODDEF
2339-
{"read", bufferediobase_read, METH_VARARGS, bufferediobase_read_doc},
2340-
{"read1", bufferediobase_read1, METH_VARARGS, bufferediobase_read1_doc},
2368+
_IO__BUFFEREDIOBASE_READ_METHODDEF
2369+
_IO__BUFFEREDIOBASE_READ1_METHODDEF
23412370
_IO__BUFFEREDIOBASE_READINTO_METHODDEF
23422371
_IO__BUFFEREDIOBASE_READINTO1_METHODDEF
2343-
{"write", bufferediobase_write, METH_VARARGS, bufferediobase_write_doc},
2372+
_IO__BUFFEREDIOBASE_WRITE_METHODDEF
23442373
{NULL, NULL}
23452374
};
23462375

Modules/_io/clinic/bufferedio.c.h

+168-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)