(self, other: "TimecodeLike")
| 666 | return to_return |
| 667 | |
| 668 | def __isub__(self, other: "TimecodeLike") -> "FrameTimecode": |
| 669 | # Narrow `other`'s internal time once so pyright can track it through the dispatch below. |
| 670 | # A bare `Timecode` is treated as its own internal time. |
| 671 | if isinstance(other, FrameTimecode): |
| 672 | other_inner = other._time |
| 673 | elif isinstance(other, Timecode): |
| 674 | other_inner = other |
| 675 | else: |
| 676 | other_inner = None |
| 677 | |
| 678 | if isinstance(self._time, Timecode) and isinstance(other_inner, Timecode): |
| 679 | if self._time.time_base == other_inner.time_base: |
| 680 | self._time = Timecode( |
| 681 | pts=max(0, self._time.pts - other_inner.pts), |
| 682 | time_base=self._time.time_base, |
| 683 | ) |
| 684 | return self |
| 685 | # Different time bases: use the finer (smaller) one for better precision. |
| 686 | time_base = min(self._time.time_base, other_inner.time_base) |
| 687 | self_pts = round(Fraction(self._time.pts) * self._time.time_base / time_base) |
| 688 | other_pts = round(Fraction(other_inner.pts) * other_inner.time_base / time_base) |
| 689 | self._time = Timecode(pts=max(0, self_pts - other_pts), time_base=time_base) |
| 690 | return self |
| 691 | |
| 692 | # If either input is a timecode, the output shall also be one. The input which isn't a |
| 693 | # timecode is converted into seconds, after which the equivalent timecode is computed. |
| 694 | if isinstance(self._time, Timecode): |
| 695 | seconds = self._get_other_as_seconds(other) |
| 696 | self._time = Timecode( |
| 697 | pts=max(0, self._time.pts - round(seconds / self._time.time_base)), |
| 698 | time_base=self._time.time_base, |
| 699 | ) |
| 700 | if self._rate is None and isinstance(other, FrameTimecode): |
| 701 | self._rate = other._rate |
| 702 | return self |
| 703 | if isinstance(other_inner, Timecode): |
| 704 | # Compute `self - other` in `other`'s time base. |
| 705 | self_pts_in_other_base = round(self.seconds / other_inner.time_base) |
| 706 | self._time = Timecode( |
| 707 | pts=max(0, self_pts_in_other_base - other_inner.pts), |
| 708 | time_base=other_inner.time_base, |
| 709 | ) |
| 710 | if self._rate is None and isinstance(other, FrameTimecode): |
| 711 | self._rate = other._rate |
| 712 | return self |
| 713 | |
| 714 | if isinstance(self._time, _Seconds) and isinstance(other_inner, _Seconds): |
| 715 | self._time = _Seconds(max(0.0, self._time.value - other_inner.value)) |
| 716 | return self |
| 717 | |
| 718 | if isinstance(self._time, _Seconds): |
| 719 | self._time = _Seconds(max(0.0, self._time.value - self._get_other_as_seconds(other))) |
| 720 | return self |
| 721 | |
| 722 | self._time = _FrameNumber(max(0, self._time.value - self._get_other_as_frames(other))) |
| 723 | return self |
| 724 | |
| 725 | def __sub__(self, other: "TimecodeLike") -> "FrameTimecode": |
nothing calls this directly
no test coverage detected