This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: io.TextIOWrapper.errors not writable
Type: behavior Stage: resolved
Components: IO Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Jeffrey.Kintscher, doerwalter
Priority: normal Keywords:

Created on 2020-08-03 18:29 by doerwalter, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (3)
msg374751 - (view) Author: Walter Dörwald (doerwalter) * (Python committer) Date: 2020-08-03 18:29
PEP 293 states the following:

"""
For stream readers/writers the errors attribute must be changeable to be able to switch between different error handling methods during the lifetime of the stream reader/writer. This is currently the case for codecs.StreamReader and codecs.StreamWriter and all their subclasses. All core codecs and probably most of the third party codecs (e.g. JapaneseCodecs) derive their stream readers/writers from these classes so this already works, but the attribute errors should be documented as a requirement.
"""

However for io.TextIOWrapper, the errors attribute can not be changed:

Python 3.8.5 (default, Jul 21 2020, 10:48:26)
[Clang 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import io
>>> s = io.TextIOWrapper(io.BytesIO())
>>> s.errors = 'replace'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: attribute 'errors' of '_io.TextIOWrapper' objects is not writable

So the errors attribute of io.TextIOWrapper should be made writable.
msg374911 - (view) Author: Jeffrey Kintscher (Jeffrey.Kintscher) * Date: 2020-08-06 00:21
I looked at the implementation in Lib/_pyio.py.  The only way to change the error handler is by calling TextIOWrapper.reconfigure() and supply the new error handler as the "errors" parameter.  For example:

>>> import io
>>> s = io.TextIOWrapper(io.BytesIO())
>>> print(s.errors)
strict
>>> s.reconfigure(errors='replace')
>>> print(s.errors)
replace
>>>
msg374922 - (view) Author: Walter Dörwald (doerwalter) * (Python committer) Date: 2020-08-06 09:44
I guess that is good enough. "Being changeable" does not necessarily mean mean "being changeable via attribute assignment".

Thanks for your research. Closing the issue as "not a bug".
History
Date User Action Args
2022-04-11 14:59:34adminsetgithub: 85637
2020-08-06 09:44:42doerwaltersetstatus: open -> closed
resolution: not a bug
messages: + msg374922

stage: resolved
2020-08-06 00:21:37Jeffrey.Kintschersetmessages: + msg374911
2020-08-05 23:37:06Jeffrey.Kintschersetnosy: + Jeffrey.Kintscher
2020-08-03 18:29:12doerwaltercreate