Skip to content

Commit 511f55c

Browse files
committed
Considered using with!
1 parent f85c21e commit 511f55c

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

adafruit_circuitplayground/bluefruit.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,9 @@ def play_mp3(self, file_name):
158158
# Play a specified file.
159159
self.stop_tone()
160160
self._speaker_enable.value = True
161-
with self._audio_out(
162-
board.SPEAKER
163-
) as audio: # pylint: disable=not-callable
164-
mp3file = audiomp3.MP3Decoder(
165-
open(file_name, "rb") # pylint: disable=consider-using-with
166-
)
161+
with self._audio_out(board.SPEAKER) as audio, audiomp3.MP3Decoder(
162+
open(file_name, "rb")
163+
) as mp3file: # pylint: disable=not-callable
167164
audio.play(mp3file)
168165
while audio.playing:
169166
pass

adafruit_circuitplayground/circuit_playground_base.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -801,10 +801,9 @@ def play_file(self, file_name):
801801
# Play a specified file.
802802
self.stop_tone()
803803
self._speaker_enable.value = True
804-
with self._audio_out(board.SPEAKER) as audio: # pylint: disable=not-callable
805-
wavefile = audiocore.WaveFile(
806-
open(file_name, "rb") # pylint: disable=consider-using-with
807-
)
804+
with self._audio_out( # pylint: disable=not-callable
805+
board.SPEAKER
806+
) as audio, audiocore.WaveFile(open(file_name, "rb")) as wavefile:
808807
audio.play(wavefile)
809808
while audio.playing:
810809
pass

0 commit comments

Comments
 (0)