[issue22387] Making tempfile.NamedTemporaryFile a class

2014-09-11 Thread Antony Lee
Antony Lee added the comment: Yes, but this will make the context-manager approach (with NamedTemporaryFile(closed=True): ) unusable, because the underlying file object will be closed before calling __enter__. I think the only reasonable way to implement this would be to have __enter__ return

[issue22387] Making tempfile.NamedTemporaryFile a class

2014-09-11 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: You can do this with a function too: def NTF(*args, closed=False, **kwargs): if closed: kwargs["delete"] = True ntf = NamedTemporaryFile(*args, **kwargs) if closed: ntf.close() return ntf -- nosy: +georg.brandl, nco

[issue22387] Making tempfile.NamedTemporaryFile a class

2014-09-11 Thread Antony Lee
Antony Lee added the comment: The initial idea was to solve #14243 (NamedTemporaryFile would be more useful on Windows if you could close it without deleting) by adding a "closed" keyword argument to the constructor of a subclass, that would set "delete" to False and then close it, e.g. class

[issue22387] Making tempfile.NamedTemporaryFile a class

2014-09-11 Thread Eric V. Smith
Eric V. Smith added the comment: Can you explain why you want to subclass them? -- nosy: +eric.smith type: -> enhancement ___ Python tracker ___

[issue22387] Making tempfile.NamedTemporaryFile a class

2014-09-11 Thread Antony Lee
New submission from Antony Lee: Currently, tempfile.TemporaryFile and tempfile.NamedTemporaryFile are functions, not classes, despite what their names suggest, preventing subclassing. It would arguably be not so easy to make TemporaryFile a class, as its return value is whatever "_io.open" re