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.

Title: os.popen() objects don't support the context manager protocol
Type: behavior Stage: needs patch
Components: Library (Lib) Versions: Python 3.1, Python 3.2
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, pitrou
Priority: normal Keywords: patch

Created on 2009-12-08 19:52 by pitrou, last changed 2022-04-11 14:56 by admin. This issue is now closed.

File name Uploaded Description Edit
with_popen.patch amaury.forgeotdarc, 2009-12-08 22:18
Messages (5)
msg96151 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2009-12-08 19:52
This works under trunk but fails under py3k:

>>> import os
>>> with os.popen("ls", "r") as f:
...  print(
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: __exit__
msg96156 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2009-12-08 22:18
Here is a patch+test
msg96158 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2009-12-08 23:46
We should also proxy other special methods. There is __iter__, __next__,
what else?
msg96160 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2009-12-08 23:58
Ah, iterating already works. Sorry for the noise.
msg96161 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2009-12-09 00:04
I added a test for iterating and committed the patch in r76723 and
r76724. Thanks!
Date User Action Args
2022-04-11 14:56:55adminsetgithub: 51710
2009-12-09 00:04:04pitrousetstatus: open -> closed
resolution: fixed
messages: + msg96161
2009-12-08 23:58:05pitrousetmessages: + msg96160
2009-12-08 23:46:28pitrousetmessages: + msg96158
2009-12-08 22:18:40amaury.forgeotdarcsetfiles: + with_popen.patch

nosy: + amaury.forgeotdarc
messages: + msg96156

keywords: + patch
2009-12-08 19:52:31pitroucreate