Skip to content

Commit 8714c32

Browse files
authored
Merge pull request #13827 from timhoffm/moviewriter-init-error
MNT: Better MovieWriter init error message
2 parents a2277af + 8c068ee commit 8714c32

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

lib/matplotlib/animation.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,9 @@ def saving(self, fig, outfile, dpi, *args, **kwargs):
235235
class MovieWriter(AbstractMovieWriter):
236236
'''Base class for writing movies.
237237
238-
This class is set up to provide for writing movie frame data to a pipe.
239-
See examples for how to use these classes.
238+
This is a base class for MovieWriter subclasses that write a movie frame
239+
data to a pipe. You cannot instantiate this class directly.
240+
See examples for how to use its subclasses.
240241
241242
Attributes
242243
----------
@@ -274,6 +275,15 @@ def __init__(self, fps=5, codec=None, bitrate=None, extra_args=None,
274275
output file. Some keys that may be of use include:
275276
title, artist, genre, subject, copyright, srcform, comment.
276277
'''
278+
if self.__class__ is MovieWriter:
279+
# TODO MovieWriter is still an abstract class and needs to be
280+
# extended with a mixin. This should be clearer in naming
281+
# and description. For now, just give a reasonable error
282+
# message to users.
283+
raise TypeError(
284+
'MovieWriter cannot be instantiated directly. Please use one '
285+
'of its subclasses.')
286+
277287
self.fps = fps
278288
self.frame_format = 'rgba'
279289

lib/matplotlib/tests/test_animation.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,11 @@ def test_null_movie_writer():
7777

7878

7979
def test_movie_writer_dpi_default():
80-
# Test setting up movie writer with figure.dpi default.
80+
class DummyMovieWriter(animation.MovieWriter):
81+
def _run(self):
82+
pass
8183

84+
# Test setting up movie writer with figure.dpi default.
8285
fig = plt.figure()
8386

8487
filename = "unused.null"
@@ -87,11 +90,7 @@ def test_movie_writer_dpi_default():
8790
bitrate = 1
8891
extra_args = ["unused"]
8992

90-
def run():
91-
pass
92-
93-
writer = animation.MovieWriter(fps, codec, bitrate, extra_args)
94-
writer._run = run
93+
writer = DummyMovieWriter(fps, codec, bitrate, extra_args)
9594
writer.setup(fig, filename)
9695
assert writer.dpi == fig.dpi
9796

0 commit comments

Comments
 (0)