[issue21363] io.TextIOWrapper always closes wrapped files

2021-06-03 Thread Marten H. van Kerkwijk
Marten H. van Kerkwijk added the comment: In astropy we are now working around the auto-closing of the underlying stream in TextIOWrapper by subclassing and overriding `__del__` to detach [1]. It would seem more elegant if `TestIOWrapper` (and really, `BufferedReader`) could gain an `closefd

[issue21363] io.TextIOWrapper always closes wrapped files

2018-10-20 Thread Mitar
Mitar added the comment: I have a similar problem that text wrapper is closing the handle, and if I want to make a workaround, it also fails: buffer = io.Bytes() with io.TextIOWrapper(buffer, encoding='utf8') as text_buffer: write_content_to(text_buffer) text_buffer.flush() text_b

[issue21363] io.TextIOWrapper always closes wrapped files

2014-05-14 Thread Armin Ronacher
Armin Ronacher added the comment: I can confirm that calling detach() in __del__ within an except block solves the issue. -- ___ Python tracker ___ _

[issue21363] io.TextIOWrapper always closes wrapped files

2014-05-14 Thread Armin Ronacher
Armin Ronacher added the comment: Ah. Misread. This is about detaching the underlying stream from TextIOWrapper. I assume this could be done in the __del__ so that would work. I'm checking this now. -- ___ Python tracker

[issue21363] io.TextIOWrapper always closes wrapped files

2014-05-14 Thread Armin Ronacher
Armin Ronacher added the comment: Detach "destroys" the stream, so it's not a solution. I can't just randomly destroy global state just because it's convenient. This is what I am doing now which seems borderline insane: https://github.com/mitsuhiko/click/blob/master/click/_compat.py#L31

[issue21363] io.TextIOWrapper always closes wrapped files

2014-05-14 Thread R. David Murray
R. David Murray added the comment: I think detach is the correct way to to this, so I'm closing the issue. -- nosy: +r.david.murray resolution: -> not a bug stage: -> resolved status: open -> closed ___ Python tracker

[issue21363] io.TextIOWrapper always closes wrapped files

2014-05-01 Thread Martin Panter
Changes by Martin Panter : -- nosy: +vadmium ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.pytho

[issue21363] io.TextIOWrapper always closes wrapped files

2014-04-27 Thread eryksun
eryksun added the comment: It works if you detach the buffer beforehand: >>> import io, sys >>> stdin = sys.stdin >>> stdin.flush() >>> correct_stdin = io.TextIOWrapper(stdin.buffer, 'utf-8') >>> correct_stdin.readline() foobar 'foobar\n' >>> correct_stdin.detach

[issue21363] io.TextIOWrapper always closes wrapped files

2014-04-27 Thread Armin Ronacher
New submission from Armin Ronacher: I'm trying to write some code that fixes a misconfigured sys.stdin on a case by case bases but unfortunately I cannot use TextIOWrapper for this because it always closes the underlying file: Python >>> import io >>> sys.stdin.encoding 'ANSI_X3.4-1968' >>>