MNT: Define Protocol for Animation.event_source - #30590
Conversation
|
mypy-stubtest complains with
I tought it would be sufficient to define this for type checking. Does mypy-stubtest need runtime definitions? If so does this mean, I have to define the protocol twice, once in the .py file and once in the pyi. file? |
|
Yes, |
9b7f8cc to
1b1d3e5
Compare
| class Animation: | ||
| frame_seq: Iterable[Artist] | ||
| event_source: Any | ||
| event_source: EventSourceProtocol |
There was a problem hiding this comment.
Animation._stop sets this attribute to None, so this annotation should still have | None, though I don't know if that could be replaced by a plain call to .stop.
There was a problem hiding this comment.
Changed to
event_source: EventSourceProtocol | None # TODO: We should remove None
It's a bit weird that we set this to None. It's a a core property of Animation and setting to None means that the Animation is not usable anymore after _stop(). This looks like early cleanup. Not sure whether that is needed.
It came in via #22561. @greglucas Was there a specific reason to remove the event source.
There was a problem hiding this comment.
I think this was to remove continuous timers. I don't recall why I didn't call "stop" on the event_source instead of removing it entirely. I wonder if there was a test / external event source that didn't implement "stop" 🤷
I think your suggestion makes sense and it was likely just overlooked previously with no specific need to clean it up.
There was a problem hiding this comment.
Ok. I still think we should do this separately. As is, we do not have any behavioral change in this PR. I'd rather merge as is and handle the logic change in a follow up (tracking issue created: #30622).
Also, event_source is a mandatory parameter and cannot be None, because Animation.__init__ calls `event_source.add_callback()`.
1b1d3e5 to
d53d7fe
Compare
Also, event_source is a mandatory parameter and cannot be None, because Animation.init calls
event_source.add_callback().