Skip to content

Commit db0ec14

Browse files
committed
FIX: Typing of FuncAnimation
`func` and `init_func` may return None (which is ok if `blit=False`). Since gating the allowed signature on the state of `blit` is not feasible, we err on the side on being too permissive in the type definition: Rather not flag a type error and only raise on runtime than complain on an actually working signature. Closes #29960.
1 parent 919d9e9 commit db0ec14

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

lib/matplotlib/animation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,8 +1769,8 @@ def _init_draw(self):
17691769
self._drawn_artists = self._init_func()
17701770
if self._blit:
17711771
if self._drawn_artists is None:
1772-
raise RuntimeError('The init_func must return a '
1773-
'sequence of Artist objects.')
1772+
raise RuntimeError('When blit=True, the init_func must '
1773+
'return a sequence of Artist objects.')
17741774
for a in self._drawn_artists:
17751775
a.set_animated(self._blit)
17761776
self._save_seq = []
@@ -1787,8 +1787,8 @@ def _draw_frame(self, framedata):
17871787

17881788
if self._blit:
17891789

1790-
err = RuntimeError('The animation function must return a sequence '
1791-
'of Artist objects.')
1790+
err = RuntimeError('When blit=True, the animation function must '
1791+
'return a sequence of Artist objects.')
17921792
try:
17931793
# check if a sequence
17941794
iter(self._drawn_artists)

lib/matplotlib/animation.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,9 @@ class FuncAnimation(TimedAnimation):
206206
def __init__(
207207
self,
208208
fig: Figure,
209-
func: Callable[..., Iterable[Artist]],
209+
func: Callable[..., Iterable[Artist] | None],
210210
frames: Iterable | int | Callable[[], Generator] | None = ...,
211-
init_func: Callable[[], Iterable[Artist]] | None = ...,
211+
init_func: Callable[[], Iterable[Artist] | None] | None = ...,
212212
fargs: tuple[Any, ...] | None = ...,
213213
save_count: int | None = ...,
214214
*,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy