summaryrefslogtreecommitdiffstats
path: root/Modules/_io/textio.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-01-16 16:34:21 (GMT)
committerGitHub <noreply@github.com>2018-01-16 16:34:21 (GMT)
commit4d9aec022063dcfc4cf40ae46b1c4a968297e664 (patch)
treed422eb5dbd9f265fca38e7315b95ab3faa66adab /Modules/_io/textio.c
parent378edee0a3b913d60653dc17dfe61d83405a8135 (diff)
downloadcpython-4d9aec022063dcfc4cf40ae46b1c4a968297e664.zip
cpython-4d9aec022063dcfc4cf40ae46b1c4a968297e664.tar.gz
cpython-4d9aec022063dcfc4cf40ae46b1c4a968297e664.tar.bz2
bpo-31572: Get rid of PyObject_HasAttr() and _PyObject_HasAttrId() in the _io module. (#3726)
Diffstat (limited to 'Modules/_io/textio.c')
-rw-r--r--Modules/_io/textio.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
index d776b5d..9f3fd2d 100644
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -29,7 +29,6 @@ _Py_IDENTIFIER(mode);
_Py_IDENTIFIER(name);
_Py_IDENTIFIER(raw);
_Py_IDENTIFIER(read);
-_Py_IDENTIFIER(read1);
_Py_IDENTIFIER(readable);
_Py_IDENTIFIER(replace);
_Py_IDENTIFIER(reset);
@@ -1202,7 +1201,17 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
goto error;
self->seekable = self->telling = r;
- self->has_read1 = _PyObject_HasAttrId(buffer, &PyId_read1);
+ res = _PyObject_GetAttrWithoutError(buffer, _PyIO_str_read1);
+ if (res != NULL) {
+ Py_DECREF(res);
+ self->has_read1 = 1;
+ }
+ else if (!PyErr_Occurred()) {
+ self->has_read1 = 0;
+ }
+ else {
+ goto error;
+ }
self->encoding_start_of_stream = 0;
if (_textiowrapper_fix_encoder_state(self) < 0) {
@@ -3013,15 +3022,9 @@ textiowrapper_newlines_get(textio *self, void *context)
CHECK_ATTACHED(self);
if (self->decoder == NULL)
Py_RETURN_NONE;
- res = PyObject_GetAttr(self->decoder, _PyIO_str_newlines);
- if (res == NULL) {
- if (PyErr_ExceptionMatches(PyExc_AttributeError)) {
- PyErr_Clear();
- Py_RETURN_NONE;
- }
- else {
- return NULL;
- }
+ res = _PyObject_GetAttrWithoutError(self->decoder, _PyIO_str_newlines);
+ if (res == NULL && !PyErr_Occurred()) {
+ Py_RETURN_NONE;
}
return res;
}