From 713241a3c1f9ed4e084c1562cf5a4c4a0770835c Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Fri, 29 Jan 2016 09:34:41 +0100 Subject: [PATCH] Prevent ResourceWarning --- patacrep/songs/__init__.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/patacrep/songs/__init__.py b/patacrep/songs/__init__.py index 3745ab9e..3a7a92d0 100644 --- a/patacrep/songs/__init__.py +++ b/patacrep/songs/__init__.py @@ -194,11 +194,12 @@ class Song: # https://bugs.python.org/issue1692335 return cached = {attr: getattr(self, attr) for attr in self.cached_attributes} - pickle.dump( - cached, - open(self.cached_name, 'wb'), - protocol=-1 - ) + with open(self.cached_name, 'wb') as cache_file: + pickle.dump( + cached, + cache_file, + protocol=-1 + ) def __str__(self): return str(self.fullpath)