File tree Expand file tree Collapse file tree
Misc/NEWS.d/next/Core and Builtins Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ Remove the hardcoded classes names from ``_io `` module classes' ``__repr__ `` in
2+ favor of the actual object type name to make it more subclass friendly.
Original file line number Diff line number Diff line change @@ -1074,22 +1074,26 @@ fileio_repr(fileio *self)
10741074 PyObject * nameobj , * res ;
10751075
10761076 if (self -> fd < 0 )
1077- return PyUnicode_FromFormat ("<_io.FileIO [closed]>" );
1077+ return PyUnicode_FromFormat (
1078+ "<%s [closed]>" ,
1079+ Py_TYPE ((PyObject * ) self )-> tp_name );
10781080
10791081 if (_PyObject_LookupAttrId ((PyObject * ) self , & PyId_name , & nameobj ) < 0 ) {
10801082 return NULL ;
10811083 }
10821084 if (nameobj == NULL ) {
10831085 res = PyUnicode_FromFormat (
1084- "<_io.FileIO fd=%d mode='%s' closefd=%s>" ,
1086+ "<%s fd=%d mode='%s' closefd=%s>" ,
1087+ Py_TYPE ((PyObject * ) self )-> tp_name ,
10851088 self -> fd , mode_string (self ), self -> closefd ? "True" : "False" );
10861089 }
10871090 else {
10881091 int status = Py_ReprEnter ((PyObject * )self );
10891092 res = NULL ;
10901093 if (status == 0 ) {
10911094 res = PyUnicode_FromFormat (
1092- "<_io.FileIO name=%R mode='%s' closefd=%s>" ,
1095+ "<%s name=%R mode='%s' closefd=%s>" ,
1096+ Py_TYPE ((PyObject * ) self )-> tp_name ,
10931097 nameobj , mode_string (self ), self -> closefd ? "True" : "False" );
10941098 Py_ReprLeave ((PyObject * )self );
10951099 }
Original file line number Diff line number Diff line change @@ -2886,7 +2886,7 @@ textiowrapper_repr(textio *self)
28862886
28872887 CHECK_INITIALIZED (self );
28882888
2889- res = PyUnicode_FromString ("<_io.TextIOWrapper" );
2889+ res = PyUnicode_FromFormat ("<%s" , Py_TYPE (( PyObject * ) self ) -> tp_name );
28902890 if (res == NULL )
28912891 return NULL ;
28922892
Original file line number Diff line number Diff line change @@ -1034,13 +1034,19 @@ static PyObject *
10341034winconsoleio_repr (winconsoleio * self )
10351035{
10361036 if (self -> handle == INVALID_HANDLE_VALUE )
1037- return PyUnicode_FromFormat ("<_io._WindowsConsoleIO [closed]>" );
1037+ return PyUnicode_FromFormat (
1038+ "<%s [closed]>" ,
1039+ Py_TYPE ((PyObject * ) self )-> tp_name );
10381040
10391041 if (self -> readable )
1040- return PyUnicode_FromFormat ("<_io._WindowsConsoleIO mode='rb' closefd=%s>" ,
1042+ return PyUnicode_FromFormat (
1043+ "<%s mode='rb' closefd=%s>" ,
1044+ Py_TYPE ((PyObject * ) self )-> tp_name ,
10411045 self -> closehandle ? "True" : "False" );
10421046 if (self -> writable )
1043- return PyUnicode_FromFormat ("<_io._WindowsConsoleIO mode='wb' closefd=%s>" ,
1047+ return PyUnicode_FromFormat (
1048+ "<%s mode='wb' closefd=%s>" ,
1049+ Py_TYPE ((PyObject * ) self )-> tp_name ,
10441050 self -> closehandle ? "True" : "False" );
10451051
10461052 PyErr_SetString (PyExc_SystemError , "_WindowsConsoleIO has invalid mode" );
You can’t perform that action at this time.
0 commit comments