Skip to content

Commit 44e06bc

Browse files
Use Argument Clinic for the getters of _WindowsConsoleIO
They are defined in a preprocessor conditional block, which is now supported.
1 parent 0abd8a6 commit 44e06bc

2 files changed

Lines changed: 133 additions & 11 deletions

File tree

Modules/_io/clinic/winconsoleio.c.h

Lines changed: 103 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_io/winconsoleio.c

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,32 +1202,52 @@ static PyMethodDef winconsoleio_methods[] = {
12021202

12031203
/* 'closed' and 'mode' are attributes for compatibility with FileIO. */
12041204

1205+
/*[clinic input]
1206+
@getter
1207+
_io._WindowsConsoleIO.closed
1208+
1209+
True if the file is closed.
1210+
[clinic start generated code]*/
1211+
12051212
static PyObject *
1206-
get_closed(PyObject *op, void *Py_UNUSED(closure))
1213+
_io__WindowsConsoleIO_closed_get_impl(winconsoleio *self)
1214+
/*[clinic end generated code: output=5a8df1a0e2bfa766 input=ece879e363f4d6bb]*/
12071215
{
1208-
winconsoleio *self = winconsoleio_CAST(op);
12091216
return PyBool_FromLong((long)(self->fd == -1));
12101217
}
12111218

1219+
/*[clinic input]
1220+
@getter
1221+
_io._WindowsConsoleIO.closefd
1222+
1223+
True if the file descriptor will be closed by close().
1224+
[clinic start generated code]*/
1225+
12121226
static PyObject *
1213-
get_closefd(PyObject *op, void *Py_UNUSED(closure))
1227+
_io__WindowsConsoleIO_closefd_get_impl(winconsoleio *self)
1228+
/*[clinic end generated code: output=e6a6c7bab25b18c9 input=155722042f7dcf53]*/
12141229
{
1215-
winconsoleio *self = winconsoleio_CAST(op);
12161230
return PyBool_FromLong((long)(self->closefd));
12171231
}
12181232

1233+
/*[clinic input]
1234+
@getter
1235+
_io._WindowsConsoleIO.mode
1236+
1237+
String giving the file mode.
1238+
[clinic start generated code]*/
1239+
12191240
static PyObject *
1220-
get_mode(PyObject *op, void *Py_UNUSED(closure))
1241+
_io__WindowsConsoleIO_mode_get_impl(winconsoleio *self)
1242+
/*[clinic end generated code: output=2d7c4cabf96e5281 input=e1fa9cd881117c0f]*/
12211243
{
1222-
winconsoleio *self = winconsoleio_CAST(op);
12231244
return PyUnicode_FromString(self->readable ? "rb" : "wb");
12241245
}
12251246

12261247
static PyGetSetDef winconsoleio_getsetlist[] = {
1227-
{"closed", get_closed, NULL, "True if the file is closed"},
1228-
{"closefd", get_closefd, NULL,
1229-
"True if the file descriptor will be closed by close()."},
1230-
{"mode", get_mode, NULL, "String giving the file mode"},
1248+
_IO__WINDOWSCONSOLEIO_CLOSED_GETSETDEF
1249+
_IO__WINDOWSCONSOLEIO_CLOSEFD_GETSETDEF
1250+
_IO__WINDOWSCONSOLEIO_MODE_GETSETDEF
12311251
{NULL},
12321252
};
12331253

0 commit comments

Comments
 (0)