Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d04b97d

Browse files
committed
Fix some minor open-without-context.
1 parent 68681da commit d04b97d

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

lib/matplotlib/afm.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
... 'fonts', 'afm', 'ptmr8a.afm')
2020
>>>
2121
>>> from matplotlib.afm import AFM
22-
>>> afm = AFM(open(afm_fname))
22+
>>> with open(afm_fname) as fh:
23+
... afm = AFM(fh)
2324
>>> afm.string_width_height('What the heck?')
2425
(6220.0, 694)
2526
>>> afm.get_fontname()

lib/matplotlib/animation.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,10 +413,9 @@ def grab_frame(self, **savefig_kwargs):
413413
try:
414414
# Tell the figure to save its data to the sink, using the
415415
# frame format and dpi.
416-
myframesink = self._frame_sink()
417-
self.fig.savefig(myframesink, format=self.frame_format,
418-
dpi=self.dpi, **savefig_kwargs)
419-
myframesink.close()
416+
with self._frame_sink() as myframesink:
417+
self.fig.savefig(myframesink, format=self.frame_format,
418+
dpi=self.dpi, **savefig_kwargs)
420419

421420
except RuntimeError:
422421
out, err = self._proc.communicate()

lib/matplotlib/tests/test_type1font.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ def test_Type1Font():
1414
font = t1f.Type1Font(filename)
1515
slanted = font.transform({'slant': 1})
1616
condensed = font.transform({'extend': 0.5})
17-
rawdata = open(filename, 'rb').read()
17+
with open(filename, 'rb') as fd:
18+
rawdata = fd.read()
1819
assert_equal(font.parts[0], rawdata[0x0006:0x10c5])
1920
assert_equal(font.parts[1], rawdata[0x10cb:0x897f])
2021
assert_equal(font.parts[2], rawdata[0x8985:0x8ba6])

0 commit comments

Comments
 (0)