Issue 12487: urllib2.urlopen() returns object missing context manager (original) (raw)

Issue12487

Created on 2011-07-04 10:18 by scode, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg139746 - (view) Author: Peter Schuller (scode) Date: 2011-07-04 10:18
The documentation states it returns a "file-like object". In Python 2.5+ I expect such file-like objects to have a context manager for use with the with statement. In my particular use-case, the lack comes from urllib.addinfourl but I have not investigated what the possible types returned may be.
msg139797 - (view) Author: Julian Berman (Julian) * Date: 2011-07-04 18:03
You probably should bring this up again on #4972 which is being worked on. (and for the immediate future you have contextlib.closing too in case you hadn't seen it already)
msg139807 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2011-07-04 21:09
It should be documented that in 2.x series the file-like object does not support context management protocol. I have added the superseder issue number, please see the note as if you really want in 2.x, how you can have it using contextlib and in 3.x the context management protocol support is available.
History
Date User Action Args
2022-04-11 14:57:19 admin set github: 56696
2011-07-04 21:09:07 orsenthil set status: open -> closedresolution: duplicatemessages: + superseder: URLopener should support context manager protocolstage: resolved
2011-07-04 18:03:05 Julian set nosy: + Julianmessages: +
2011-07-04 16:34:50 ned.deily set nosy: + orsenthil
2011-07-04 10🔞24 scode create