@@ -924,14 +924,10 @@ _textiowrapper_set_encoder(textio *self, PyObject *codec_info,
924924 return -1 ;
925925
926926 /* Get the normalized named of the codec */
927- res = _PyObject_GetAttrId (codec_info , & PyId_name );
928- if (res == NULL ) {
929- if (PyErr_ExceptionMatches (PyExc_AttributeError ))
930- PyErr_Clear ();
931- else
932- return -1 ;
927+ if (_PyObject_LookupAttrId (codec_info , & PyId_name , & res ) < 0 ) {
928+ return -1 ;
933929 }
934- else if (PyUnicode_Check (res )) {
930+ if (res != NULL && PyUnicode_Check (res )) {
935931 const encodefuncentry * e = encodefuncs ;
936932 while (e -> name != NULL ) {
937933 if (_PyUnicode_EqualToASCIIString (res , e -> name )) {
@@ -1177,19 +1173,17 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
11771173
11781174 if (Py_TYPE (buffer ) == & PyBufferedReader_Type ||
11791175 Py_TYPE (buffer ) == & PyBufferedWriter_Type ||
1180- Py_TYPE (buffer ) == & PyBufferedRandom_Type ) {
1181- raw = _PyObject_GetAttrId (buffer , & PyId_raw );
1176+ Py_TYPE (buffer ) == & PyBufferedRandom_Type )
1177+ {
1178+ if (_PyObject_LookupAttrId (buffer , & PyId_raw , & raw ) < 0 )
1179+ goto error ;
11821180 /* Cache the raw FileIO object to speed up 'closed' checks */
1183- if (raw = = NULL ) {
1184- if (PyErr_ExceptionMatches ( PyExc_AttributeError ) )
1185- PyErr_Clear () ;
1181+ if (raw ! = NULL ) {
1182+ if (Py_TYPE ( raw ) == & PyFileIO_Type )
1183+ self -> raw = raw ;
11861184 else
1187- goto error ;
1185+ Py_DECREF ( raw ) ;
11881186 }
1189- else if (Py_TYPE (raw ) == & PyFileIO_Type )
1190- self -> raw = raw ;
1191- else
1192- Py_DECREF (raw );
11931187 }
11941188
11951189 res = _PyObject_CallMethodId (buffer , & PyId_seekable , NULL );
@@ -1201,17 +1195,12 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer,
12011195 goto error ;
12021196 self -> seekable = self -> telling = r ;
12031197
1204- res = _PyObject_GetAttrWithoutError (buffer , _PyIO_str_read1 );
1205- if (res != NULL ) {
1206- Py_DECREF (res );
1207- self -> has_read1 = 1 ;
1208- }
1209- else if (!PyErr_Occurred ()) {
1210- self -> has_read1 = 0 ;
1211- }
1212- else {
1198+ r = _PyObject_LookupAttr (buffer , _PyIO_str_read1 , & res );
1199+ if (r < 0 ) {
12131200 goto error ;
12141201 }
1202+ Py_XDECREF (res );
1203+ self -> has_read1 = r ;
12151204
12161205 self -> encoding_start_of_stream = 0 ;
12171206 if (_textiowrapper_fix_encoder_state (self ) < 0 ) {
@@ -3020,10 +3009,9 @@ textiowrapper_newlines_get(textio *self, void *context)
30203009{
30213010 PyObject * res ;
30223011 CHECK_ATTACHED (self );
3023- if (self -> decoder == NULL )
3024- Py_RETURN_NONE ;
3025- res = _PyObject_GetAttrWithoutError (self -> decoder , _PyIO_str_newlines );
3026- if (res == NULL && !PyErr_Occurred ()) {
3012+ if (self -> decoder == NULL ||
3013+ _PyObject_LookupAttr (self -> decoder , _PyIO_str_newlines , & res ) == 0 )
3014+ {
30273015 Py_RETURN_NONE ;
30283016 }
30293017 return res ;
0 commit comments