Repository: ManimCommunity/manim
File: manim/_config/utils.py (Python)

Code before:
    def quality(self):
        """Video quality (-q)."""
        keys = ["pixel_width", "pixel_height", "frame_rate"]
        q = {k: self[k] for k in keys}
        for qual in constants.QUALITIES:
            if all([q[k] == constants.QUALITIES[qual][k] for k in keys]):
                return qual
        return None

    @quality.setter
    def quality(self, qual: str) -> None:
        if qual not in constants.QUALITIES:
            raise KeyError(f"quality must be one of {list(constants.QUALITIES.keys())}")
        q = constants.QUALITIES[qual]
        self.frame_size = q["pixel_width"], q["pixel_height"]
        self.frame_rate = q["frame_rate"]

    @property
    def transparent(self):
        """Whether the background opacity is 0.0 (-t)."""
        return self._d["background_opacity"] == 0.0

    @transparent.setter
    def transparent(self, val: bool) -> None:
        self._d["background_opacity"] = float(not val)
        self.resolve_movie_file_extension(val)

    @property
    def dry_run(self):
        """Whether dry run is enabled."""
        return (
            self.write_to_movie is False
            and self.write_all is False
            and self.save_last_frame is False
            and self.save_pngs is False
            and self.save_as_gif is False
        )

    @dry_run.setter
    def dry_run(self, val: bool) -> None:
        if val:
            self.write_to_movie = False
            self.write_all = False
            self.save_last_frame = False
            self.save_pngs = False
            self.save_as_gif = False
        else:
            raise ValueError(
                "It is unclear what it means to set dry_run to "
                "False.  Instead, try setting each option "
                "individually. (write_to_movie, write_all, "

Review comment (bug):
Wouldn't the correct way to "fix this" be to add a `break` statement above? Though for some reason this did not break Manim despite being here for a long time. I would prefer this "fix" to be taken out of this PR, and be fixed (if it is actually broken) in another PR.

Code after:
    )

    background_opacity = property(
        lambda self: self._d["background_opacity"],
        lambda self, val: self._set_between("background_opacity", val, 0, 1),
        doc="A number between 0.0 (fully transparent) and 1.0 (fully opaque).",
    )

    frame_size = property(
        lambda self: (self._d["pixel_width"], self._d["pixel_height"]),
        lambda self, tup: (
            self._d.__setitem__("pixel_width", tup[0])
            or self._d.__setitem__("pixel_height", tup[1])
        ),
        doc="Tuple with (pixel width, pixel height) (no flag).",
    )

    @property
    def quality(self):
        """Video quality (-q)."""
        keys = ["pixel_width", "pixel_height", "frame_rate"]
        q = {k: self[k] for k in keys}
        for qual in constants.QUALITIES:
            if all([q[k] == constants.QUALITIES[qual][k] for k in keys]):
                return qual
        return None

    @quality.setter
    def quality(self, qual: str) -> None:
        if qual not in constants.QUALITIES:
            raise KeyError(f"quality must be one of {list(constants.QUALITIES.keys())}")
        q = constants.QUALITIES[qual]
        self.frame_size = q["pixel_width"], q["pixel_height"]
        self.frame_rate = q["frame_rate"]

    @property
    def transparent(self):
        """Whether the background opacity is 0.0 (-t)."""
        return self._d["background_opacity"] == 0.0

    @transparent.setter
    def transparent(self, val: bool) -> None:
        self._d["background_opacity"] = float(not val)
        self.resolve_movie_file_extension(val)

    @property
    def dry_run(self):
        """Whether dry run is enabled."""
        return (
            self.write_to_movie is False
            and self.write_all is False