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: Python 2.7.0's BZ2File does not support with-statements
Type: Stage: resolved
Components: Documentation Versions: Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: weird oddity with bz2 context manager
View: 9928
Assigned To: docs@python Nosy List: docs@python, ned.deily, xZise
Priority: normal Keywords:

Created on 2015-06-07 17:45 by xZise, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg244962 - (view) Author: Fabian (xZise) * Date: 2015-06-07 17:45
I had a weird bug recently where someone tried to use the with-statement on a BZ2File. According to the documentation it was added in 2.7 and looking at https://hg.python.org/cpython/rev/5d5d9074f4ca it looks like it was added together with the support in gzip.

But after I've installed 2.7.0 I could use the with-statement on gzip but not in BZ2File:

Python 2.7 (r27:82500, Jun  7 2015, 19:01:29) 
[GCC 4.8.3 20140911 (Red Hat 4.8.3-7)] on linux3
Type "help", "copyright", "credits" or "license" for more information.
>>> import bz2
>>> with bz2.BZ2File('tests/data/xml/article-pyrus.xml.bz2') as f:
...   c = f.read()
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: __exit__

So I've installed 2.7.1 and sure enough it works there:

Python 2.7.1 (r271:86832, Jun  7 2015, 19:21:02) 
[GCC 4.8.3 20140911 (Red Hat 4.8.3-7)] on linux3
Type "help", "copyright", "credits" or "license" for more information.
>>> import bz2
>>> with bz2.BZ2File('tests/data/xml/article-pyrus.xml.bz2') as f:
...   c = f.read()
... 
>>> 

I guess the documentation needs be updated that since Python 2.7.1 BZ2File supports the with-statement.

See also: https://phabricator.wikimedia.org/T101649
msg244982 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2015-06-08 01:07
The misbehavior in Python 2.7 was due to a bug as documented in Issue9928, a bug that unfortunately was not discovered until just after 2.7 was initially released.  The fix for Issue9928 was first included in 2.7.1 as you discovered.  So the documentation has always been correct in intent.  For Python versions in maintenance mode, like 2.7.x and 3.4.x, we only provide fixes for the most recent minor release of each (e.g. currently 2.7.10 and 3.4.3), so Python 2.7 was no longer supported once Python 2.7.1 was released and those events were nearly five years and many minor versions ago.  It's a bit of a judgement call in this case but I don't think there's a compelling reason to change the documentation now.  The current version of the 2.7 documentation is intended to reflect the current state of Python 2.7, e.g. 2.7.10, which it does.  And we hope that no one is still using 2.7(.0).
History
Date User Action Args
2022-04-11 14:58:17adminsetgithub: 68592
2015-06-08 01:07:32ned.deilysetstatus: open -> closed

superseder: weird oddity with bz2 context manager

nosy: + ned.deily
messages: + msg244982
resolution: duplicate
stage: resolved
2015-06-07 17:45:24xZisecreate