[issue2021] Turn NamedTemporaryFile into a context manager

2008-02-11 Thread Nick Coghlan
Nick Coghlan added the comment: Backported to 2.5 in r60728 P.S. To elaborate a bit more on why converting NamedTemporaryFile to subclass file would be a much bigger deal than it is to just fix its __enter__ and __exit__ methods: - converts from old-style to new-style class - imposes the constra

[issue2021] Turn NamedTemporaryFile into a context manager

2008-02-11 Thread Nick Coghlan
Nick Coghlan added the comment: The wrapper approach has the virtue of providing easy access to the underlying file object and its methods. That actually gets a bit more difficult when you switch to a subclassing approach (you need to either explicitly qualify the methods or play around with supe

[issue2021] Turn NamedTemporaryFile into a context manager

2008-02-10 Thread Alexander Belopolsky
Alexander Belopolsky added the comment: Nick's comment made me think why NamedTemporaryFile can't simply subclass file and get properly working context manager's methods for free. It turned out that although file is subclassable, in its present form, it does not allow NamedTemporaryFile imple

[issue2021] Turn NamedTemporaryFile into a context manager

2008-02-09 Thread Nick Coghlan
Nick Coghlan added the comment: I've changed the issue type from rfe to behaviour. NamedTemporaryFile actually provides __enter__ and __exit__ methods in 2.5, they just don't work (it tries to use the methods from the underlying file object directly which turns out to be a doomed exercise for a c

[issue2021] Turn NamedTemporaryFile into a context manager

2008-02-09 Thread Nick Coghlan
Changes by Nick Coghlan: -- assignee: -> ncoghlan nosy: +ncoghlan __ Tracker <[EMAIL PROTECTED]> __ ___ Python-bugs-list mailing list Unsubscr

[issue2021] Turn NamedTemporaryFile into a context manager

2008-02-06 Thread Christian Heimes
Christian Heimes added the comment: Thanks for the patch! It even has a unit test, very good. :) The __future__ statement isn't necessary for Python 2.6. The with statement is always available. -- nosy: +tiran priority: -> normal type: behavior -> rfe _

[issue2021] Turn NamedTemporaryFile into a context manager

2008-02-06 Thread Raghuram Devarakonda
Changes by Raghuram Devarakonda: -- keywords: +patch __ Tracker <[EMAIL PROTECTED]> __ ___ Python-bugs-list mailing list Unsubscribe: http://m

[issue2021] Turn NamedTemporaryFile into a context manager

2008-02-06 Thread Alexander Belopolsky
New submission from Alexander Belopolsky: In the spirit of files becoming context managers in 2.5, the attached patch defines __enter__ and __exit__ methods for tempfile.NamedTemporaryFile. BTW, I was not able to add a "patch" keyword which seems appropriate here. -- components: Library