diff --git a/Readme.md b/Readme.md index 9305517..cbde5e4 100644 --- a/Readme.md +++ b/Readme.md @@ -22,6 +22,8 @@ game specific things: ### v1.10 - Moved a few warnings to go through Python's system, so they get attributed to the right place. +- Added a warning for initializing a non-integer slider option with `is_integer=True` (the default). + - Added support for BL1. ### v1.9 diff --git a/options.py b/options.py index d603676..4d039c5 100644 --- a/options.py +++ b/options.py @@ -225,6 +225,17 @@ def __post_init__(self) -> None: if self.step > (self.max_value - self.min_value): raise ValueError("Can't give slider option a step larger than its allowed range") + # This isn't as serious, but still show a warning + if self.is_integer and any( + x != int(x) for x in (self.value, self.min_value, self.max_value, self.step) + ): + warnings.warn( + "Spinner has non-integer fields despite is_integer being True. This may cause" + " unexpected rounding.", + # +1 to skip the generated dataclass `__init__` too + stacklevel=3, + ) + def _from_json(self, value: JSON) -> None: try: self.value = float(value) # type: ignore