Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3072202

Browse files
corona10aisk
authored andcommittedFeb 11, 2024
pythongh-112205: Update textio module to use @getter as possible. (pythongh-113095)
1 parent 60cc190 commit 3072202

File tree

2 files changed

+125
-49
lines changed

2 files changed

+125
-49
lines changed
 

‎Modules/_io/clinic/textio.c.h

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

‎Modules/_io/textio.c

+36-48
Original file line numberDiff line numberDiff line change
@@ -1475,7 +1475,7 @@ textiowrapper_traverse(textio *self, visitproc visit, void *arg)
14751475
}
14761476

14771477
static PyObject *
1478-
textiowrapper_closed_get(textio *self, void *context);
1478+
_io_TextIOWrapper_closed_get_impl(textio *self);
14791479

14801480
/* This macro takes some shortcuts to make the common case faster. */
14811481
#define CHECK_CLOSED(self) \
@@ -1486,7 +1486,7 @@ textiowrapper_closed_get(textio *self, void *context);
14861486
if (self->raw != NULL) \
14871487
r = _PyFileIO_closed(self->raw); \
14881488
else { \
1489-
_res = textiowrapper_closed_get(self, NULL); \
1489+
_res = _io_TextIOWrapper_closed_get_impl(self); \
14901490
if (_res == NULL) \
14911491
return NULL; \
14921492
r = PyObject_IsTrue(_res); \
@@ -3090,7 +3090,7 @@ _io_TextIOWrapper_close_impl(textio *self)
30903090
int r;
30913091
CHECK_ATTACHED(self);
30923092

3093-
res = textiowrapper_closed_get(self, NULL);
3093+
res = _io_TextIOWrapper_closed_get_impl(self);
30943094
if (res == NULL)
30953095
return NULL;
30963096
r = PyObject_IsTrue(res);
@@ -3164,42 +3164,43 @@ textiowrapper_iternext(textio *self)
31643164
return line;
31653165
}
31663166

3167+
/*[clinic input]
3168+
@critical_section
3169+
@getter
3170+
_io.TextIOWrapper.name
3171+
[clinic start generated code]*/
3172+
31673173
static PyObject *
3168-
textiowrapper_name_get_impl(textio *self, void *context)
3174+
_io_TextIOWrapper_name_get_impl(textio *self)
3175+
/*[clinic end generated code: output=8c2f1d6d8756af40 input=26ecec9b39e30e07]*/
31693176
{
31703177
CHECK_ATTACHED(self);
31713178
return PyObject_GetAttr(self->buffer, &_Py_ID(name));
31723179
}
31733180

3174-
static PyObject *
3175-
textiowrapper_name_get(textio *self, void *context)
3176-
{
3177-
PyObject *result = NULL;
3178-
Py_BEGIN_CRITICAL_SECTION(self);
3179-
result = textiowrapper_name_get_impl(self, context);
3180-
Py_END_CRITICAL_SECTION();
3181-
return result;
3182-
}
3181+
/*[clinic input]
3182+
@critical_section
3183+
@getter
3184+
_io.TextIOWrapper.closed
3185+
[clinic start generated code]*/
31833186

31843187
static PyObject *
3185-
textiowrapper_closed_get_impl(textio *self, void *context)
3188+
_io_TextIOWrapper_closed_get_impl(textio *self)
3189+
/*[clinic end generated code: output=b49b68f443a85e3c input=7dfcf43f63c7003d]*/
31863190
{
31873191
CHECK_ATTACHED(self);
31883192
return PyObject_GetAttr(self->buffer, &_Py_ID(closed));
31893193
}
31903194

3191-
static PyObject *
3192-
textiowrapper_closed_get(textio *self, void *context)
3193-
{
3194-
PyObject *result = NULL;
3195-
Py_BEGIN_CRITICAL_SECTION(self);
3196-
result = textiowrapper_closed_get_impl(self, context);
3197-
Py_END_CRITICAL_SECTION();
3198-
return result;
3199-
}
3195+
/*[clinic input]
3196+
@critical_section
3197+
@getter
3198+
_io.TextIOWrapper.newlines
3199+
[clinic start generated code]*/
32003200

32013201
static PyObject *
3202-
textiowrapper_newlines_get_impl(textio *self, void *context)
3202+
_io_TextIOWrapper_newlines_get_impl(textio *self)
3203+
/*[clinic end generated code: output=53aa03ac35573180 input=610df647e514b3e8]*/
32033204
{
32043205
PyObject *res;
32053206
CHECK_ATTACHED(self);
@@ -3211,33 +3212,20 @@ textiowrapper_newlines_get_impl(textio *self, void *context)
32113212
return res;
32123213
}
32133214

3214-
static PyObject *
3215-
textiowrapper_newlines_get(textio *self, void *context)
3216-
{
3217-
PyObject *result = NULL;
3218-
Py_BEGIN_CRITICAL_SECTION(self);
3219-
result = textiowrapper_newlines_get_impl(self, context);
3220-
Py_END_CRITICAL_SECTION();
3221-
return result;
3222-
}
3215+
/*[clinic input]
3216+
@critical_section
3217+
@getter
3218+
_io.TextIOWrapper.errors
3219+
[clinic start generated code]*/
32233220

32243221
static PyObject *
3225-
textiowrapper_errors_get_impl(textio *self, void *context)
3222+
_io_TextIOWrapper_errors_get_impl(textio *self)
3223+
/*[clinic end generated code: output=dca3a3ef21b09484 input=b45f983e6d43c4d8]*/
32263224
{
32273225
CHECK_INITIALIZED(self);
32283226
return Py_NewRef(self->errors);
32293227
}
32303228

3231-
static PyObject *
3232-
textiowrapper_errors_get(textio *self, void *context)
3233-
{
3234-
PyObject *result = NULL;
3235-
Py_BEGIN_CRITICAL_SECTION(self);
3236-
result = textiowrapper_errors_get_impl(self, context);
3237-
Py_END_CRITICAL_SECTION();
3238-
return result;
3239-
}
3240-
32413229
/*[clinic input]
32423230
@critical_section
32433231
@getter
@@ -3349,12 +3337,12 @@ static PyMemberDef textiowrapper_members[] = {
33493337
};
33503338

33513339
static PyGetSetDef textiowrapper_getset[] = {
3352-
{"name", (getter)textiowrapper_name_get, NULL, NULL},
3353-
{"closed", (getter)textiowrapper_closed_get, NULL, NULL},
3340+
_IO_TEXTIOWRAPPER_NAME_GETSETDEF
3341+
_IO_TEXTIOWRAPPER_CLOSED_GETSETDEF
33543342
/* {"mode", (getter)TextIOWrapper_mode_get, NULL, NULL},
33553343
*/
3356-
{"newlines", (getter)textiowrapper_newlines_get, NULL, NULL},
3357-
{"errors", (getter)textiowrapper_errors_get, NULL, NULL},
3344+
_IO_TEXTIOWRAPPER_NEWLINES_GETSETDEF
3345+
_IO_TEXTIOWRAPPER_ERRORS_GETSETDEF
33583346
_IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF
33593347
{NULL}
33603348
};

0 commit comments

Comments
 (0)
Please sign in to comment.