This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: bz2.BZ2File should support "with" protocol per PEP 343
Type: behavior Stage: resolved
Components: Extension Modules Versions: Python 2.6
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: Matt.Wartell, r.david.murray, tseaver
Priority: normal Keywords:

Created on 2010-05-03 06:54 by Matt.Wartell, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (5)
msg104817 - (view) Author: Matt Wartell (Matt.Wartell) Date: 2010-05-03 06:54
As the bz2.BZ2File object claims to be a file-like object it should conform to PEP 343 "The 'with' statement" by implementation of the __enter__ and __exit__ methods.


boring, substantiating detail follows:
$ uname -a
Linux tallguy 2.6.32-21-generic #32-Ubuntu SMP Fri Apr 16 08:10:02 UTC 2010 i686 GNU/Linux
$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) 
[GCC 4.4.3] on linux2
>>> with bz2.BZ2File('test.bz2') as infile:
...     pass
... 
AttributeError: 'bz2.BZ2File' object has no attribute '__exit__'

>>> getattr(bz2.BZ2File, '__enter__')
AttributeError: type object 'bz2.BZ2File' has no attribute '__enter__'
>>> getattr(bz2.BZ2File, '__exit__')
AttributeError: type object 'bz2.BZ2File' has no attribute '__exit__'


$ dpkg -l python2.6
ii  python2.6    2.6.5-1ubuntu6     An interactive hig...
$ dpkg -L python2.6 | grep bz2.so
/usr/lib/python2.6/lib-dynload/bz2.so
msg104819 - (view) Author: Matt Wartell (Matt.Wartell) Date: 2010-05-03 07:06
cross referenced with documentation issue http://bugs.python.org/issue8602 "documentation of bz2 module mildly erroneous"
msg104841 - (view) Author: Tres Seaver (tseaver) * Date: 2010-05-03 14:45
BZ2File objects already support the context manager protocol on the trunk, as of Antoine Pitrou's fix for http://bugs.python.org/issue3860
msg104844 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-05-03 15:09
Indeed, and it was considered a feature request and thus is not appropriate for backport.  If you wish to see that decision changed I think you will need to appeal to python-dev.
msg104858 - (view) Author: Matt Wartell (Matt.Wartell) Date: 2010-05-03 17:38
Sorry for the dup, and thanks for the patch. 

My patch for Module/bz2module.c was almost done - I learned a lot in the process, but foremost to check better for dups, first ;)
History
Date User Action Args
2022-04-11 14:57:00adminsetgithub: 52847
2010-05-03 17:38:07Matt.Wartellsetmessages: + msg104858
2010-05-03 15:09:39r.david.murraysetstatus: open -> closed

versions: + Python 2.6, - Python 3.2
nosy: + r.david.murray

messages: + msg104844
resolution: out of date
stage: needs patch -> resolved
2010-05-03 14:45:08tseaversetnosy: + tseaver
messages: + msg104841
2010-05-03 13:37:03brian.curtinsetstage: needs patch
versions: + Python 3.2, - Python 2.6
2010-05-03 07:06:50Matt.Wartellsetmessages: + msg104819
2010-05-03 06:54:28Matt.Wartellcreate