From 4335806ca26b8c88d853b3ff34ac56d6df429aae Mon Sep 17 00:00:00 2001 From: retouching <33735357+retouching@users.noreply.github.com> Date: Sun, 14 Apr 2024 13:21:11 +0200 Subject: [PATCH] fix(Video): Allow specifying width/height as str, cast to int We simply check the type near the top of the constructor, and later in the code it casts to int and handles failures there too (e.g., if the str is not a number, it will be handled). --- devine/core/tracks/video.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/devine/core/tracks/video.py b/devine/core/tracks/video.py index b06a118..dd147b4 100644 --- a/devine/core/tracks/video.py +++ b/devine/core/tracks/video.py @@ -194,9 +194,9 @@ class Video(Track): raise TypeError(f"Expected range_ to be a {Video.Range}, not {range_!r}") if not isinstance(bitrate, (str, int, float, type(None))): raise TypeError(f"Expected bitrate to be a {str}, {int}, or {float}, not {bitrate!r}") - if not isinstance(width, (int, type(None))): + if not isinstance(width, (int, str, type(None))): raise TypeError(f"Expected width to be a {int}, not {width!r}") - if not isinstance(height, (int, type(None))): + if not isinstance(height, (int, str, type(None))): raise TypeError(f"Expected height to be a {int}, not {height!r}") if not isinstance(fps, (str, int, float, type(None))): raise TypeError(f"Expected fps to be a {str}, {int}, or {float}, not {fps!r}") @@ -212,12 +212,12 @@ class Video(Track): try: self.width = int(width or 0) or None except ValueError as e: - raise ValueError(f"Expected width to be a number, {e}") + raise ValueError(f"Expected width to be a number, not {width!r}, {e}") try: self.height = int(height or 0) or None except ValueError as e: - raise ValueError(f"Expected height to be a number, {e}") + raise ValueError(f"Expected height to be a number, not {height!r}, {e}") try: self.fps = (FPS.parse(str(fps)) or None) if fps else None