From 6452c8f883c2531aea8fbb39e33228a58569ab76 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Tue, 26 May 2015 11:28:03 +0200 Subject: [PATCH] PyQIODevice: Add context manager support. --- qutebrowser/utils/qtutils.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/qutebrowser/utils/qtutils.py b/qutebrowser/utils/qtutils.py index dc88b8c22..6573306ab 100644 --- a/qutebrowser/utils/qtutils.py +++ b/qutebrowser/utils/qtutils.py @@ -260,10 +260,15 @@ class PyQIODevice(io.BufferedIOBase): Args: mode: QIODevice::OpenMode flags. + + Return: + A contextlib.closing() object so this can be used as + contextmanager. """ ok = self.dev.open(mode) if not ok: raise OSError(self.dev.errorString()) + return contextlib.closing(self) def close(self): """Close the underlying device."""