diff --git a/Lib/_pyio.py b/Lib/_pyio.py index 2a6e7a8..82e4b61 100644 --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -759,7 +759,7 @@ class _BufferedIOMixin(BufferedIOBase): clsname = self.__class__.__name__ try: name = self.name - except AttributeError: + except (AttributeError, ValueError): return "<_pyio.{0}>".format(clsname) else: return "<_pyio.{0} name={1!r}>".format(clsname, name) @@ -1506,7 +1506,7 @@ class TextIOWrapper(TextIOBase): def __repr__(self): try: name = self.name - except AttributeError: + except (AttributeError, ValueError): return "<_pyio.TextIOWrapper encoding={0!r}>".format(self.encoding) else: return "<_pyio.TextIOWrapper name={0!r} encoding={1!r}>".format( diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c index 55c0a23..0549e7f 100644 --- a/Modules/_io/bufferedio.c +++ b/Modules/_io/bufferedio.c @@ -1195,7 +1195,8 @@ buffered_repr(buffered *self) nameobj = PyObject_GetAttrString((PyObject *) self, "name"); if (nameobj == NULL) { - if (PyErr_ExceptionMatches(PyExc_AttributeError)) + if (PyErr_ExceptionMatches(PyExc_AttributeError) + || PyErr_ExceptionMatches(PyExc_ValueError)) PyErr_Clear(); else return NULL; diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index 2559714..a8d3e3b 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -2329,7 +2329,8 @@ textiowrapper_repr(textio *self) nameobj = PyObject_GetAttrString((PyObject *) self, "name"); if (nameobj == NULL) { - if (PyErr_ExceptionMatches(PyExc_AttributeError)) + if (PyErr_ExceptionMatches(PyExc_AttributeError) + || PyErr_ExceptionMatches(PyExc_ValueError)) PyErr_Clear(); else return NULL;