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 implementation for the following reasons: 1. os.fdopen cannot create a subclass of file. 2. file.__exit__ does not call subclass' close method. The attached patch fixes both issues and reimplements NamedTemporaryFile. I understand that adding new functionality to file objects should be brought up on python-dev, but I would like to hear comments from the "nosy list" first. The patch is proof-of-concept quality at the moment and may not work non-posix platforms. Added file: http://bugs.python.org/file9401/subclass-file.diff __________________________________ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue2021> __________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com