New submission from mirabilos <[email protected]>:
The following is not possible:
with open('/tmp/x.ssv', 'r', newline='\n') as f:
f.readline()
# imagine a library call boundary here
if hasattr(f, 'reconfigure'):
f.reconfigure(newline='\n')
The .reconfigure() call would not do anything, but it errors out nevertheless,
simply because it is called (from reading the
_io_TextIOWrapper_reconfigure_impl code in Modules/_io/textio.c).
Unfortunately, I *have* to call this in my library because I have to rely on
“newline='\n'” behaviour (the hasattr avoids erroring out on binary streams),
and the normal behaviour of erroring out if it’s too late to change is also
good for me.
But the behaviour of erroring out if called at all when anything has already
been read is a problem. This can easily be solved without breaking backwards
compatibility, as the operation is a nop.
To clarify: I wish for…
with open('/tmp/x.ssv', 'r', newline='\n') as f:
f.readline()
# imagine a library call boundary here
if hasattr(f, 'reconfigure'):
f.reconfigure(newline='\n')
… to work, but for…
with open('/tmp/x.ssv', 'r') as f:
f.readline()
# imagine a library call boundary here
if hasattr(f, 'reconfigure'):
f.reconfigure(newline='\n')
… (line 1 is the only changed one) to continue to error out.
----------
components: IO
messages: 412935
nosy: mirabilos
priority: normal
severity: normal
status: open
title: _io_TextIOWrapper_reconfigure_impl errors out too early
versions: Python 3.9
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue46695>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com