Skip to content

Commit 2efeabe

Browse files
authored
Merge pull request #27 from adafruit/patch-fix
Linted
2 parents e62b27c + db17bbe commit 2efeabe

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

adafruit_pyoa.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,12 @@ def load_game(self, game_directory):
173173
)
174174
self._gamefilename = game_directory + "/cyoa.json"
175175
try:
176-
game_file = open(self._gamefilename, "r")
176+
with open( # pylint: disable=unspecified-encoding
177+
self._gamefilename, "r"
178+
) as game_file:
179+
self._game = json.load(game_file)
177180
except OSError as err:
178181
raise OSError("Could not open game file " + self._gamefilename) from err
179-
self._game = json.load(game_file)
180-
game_file.close()
181182

182183
def _fade_to_black(self):
183184
"""Turn down the lights."""
@@ -343,7 +344,7 @@ def play_sound(self, filename, *, wait_to_finish=True, loop=False):
343344
except AttributeError:
344345
self._display.wait_for_frame()
345346
try:
346-
self._wavfile = open(filename, "rb")
347+
self._wavfile = open(filename, "rb") # pylint: disable=consider-using-with
347348
except OSError as err:
348349
raise OSError("Could not locate sound file", filename) from err
349350

@@ -403,8 +404,10 @@ def set_background(self, filename, *, with_fade=True):
403404
if filename:
404405
if self._background_file:
405406
self._background_file.close()
406-
self._background_file = open(self._gamedirectory + "/" + filename, "rb")
407-
background = displayio.OnDiskBitmap(self._background_file)
407+
with open(
408+
self._gamedirectory + "/" + filename, "rb"
409+
) as self._background_file:
410+
background = displayio.OnDiskBitmap(self._background_file)
408411
self._background_sprite = displayio.TileGrid(
409412
background,
410413
pixel_shader=getattr(

0 commit comments

Comments
 (0)