From 488535adcd1d3f6271d601d86cb8cb0ebc29bbf2 Mon Sep 17 00:00:00 2001 From: Titus Date: Fri, 27 Nov 2026 07:38:32 +0100 Subject: [PATCH 1/2] 0.156.2: format_duration reads a non-string step_name as absent, and words a whole count exactly A step_name of the wrong kind raised TypeError; the calendar profile reads an optional key of the wrong kind as absent, so the duration is worded in the grain. A whole count was rounded through n * 100, which is not exact past 2^53 / 100: 9007199254740990 steps came back as 9007199254740989 days. The npm SDK's formatDuration moves the same way. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 5 +++++ src/onlyworlds/_version.py | 2 +- src/onlyworlds/calendar.py | 5 +++-- tests/test_calendar.py | 11 +++++++++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4eded70..f4db7a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ The package version runs on its own semver; the schema it is generated from is ` ## Unreleased +## 0.156.2 (2026-11-27) + +- **Fixed: `calendar.format_duration` no longer raises on a `step_name` that is not a string.** Such a value reads as absent and the duration is worded in the grain, the calendar profile's rule for an optional key of the wrong kind (a `step_name` of `5` raised `TypeError`). +- **Fixed: `calendar.format_duration` words a whole count exactly up to the safe integers.** The count was rounded to two decimals through `n * 100`, which is not exact past 2^53 / 100, so `9007199254740990` steps were worded as `9007199254740989 days`. A whole count is now shown as it is; a fractional one is rounded as before. The npm SDK's `formatDuration` gives the same answers. + ## 0.156.1 (2026-11-27) - **Fixed: the depth check before a parse took time growing with the square of a text's length.** Since 0.155.0 every reader of a file this package did not write (`read_folder`, `read_world_file`, the import doors) first counts the text's nesting, and that scan cut the strings out with a pattern that, on a string left open, retried from every quote to the end of the text: a 16 KB file of escaped quotes took about a second, and a 1 MB one would take about an hour. Valid JSON heavy with quotes read several times slower than before the check. The scan is now one pass over the brackets, quotes and backslashes, linear in the length, with the same answers: held to the old reading on 20,000 random texts, and a 40 KB text of that shape is timed (the old scan took 6.7 s on it). diff --git a/src/onlyworlds/_version.py b/src/onlyworlds/_version.py index e994588..a3effe5 100644 --- a/src/onlyworlds/_version.py +++ b/src/onlyworlds/_version.py @@ -1 +1 @@ -__version__ = "0.156.1" +__version__ = "0.156.2" diff --git a/src/onlyworlds/calendar.py b/src/onlyworlds/calendar.py index aec3ddb..0986a5a 100644 --- a/src/onlyworlds/calendar.py +++ b/src/onlyworlds/calendar.py @@ -1579,7 +1579,7 @@ def format_duration(cfg: Mapping[str, Any], steps: float) -> str: ``12 days`` in the calendar's word for a step.""" n = abs(_in(steps)) word = _prop(cfg, "step_name") - if _nullish(word): + if not isinstance(word, str): # a step_name that is not a string reads as absent (the profile's rule for an optional key of the wrong kind) word = _prop(cfg, "grain") if _nullish(word): word = "step" @@ -1599,7 +1599,8 @@ def plural(w: str, v: float) -> str: years = _div(n, _to_number(year_len)) rounded = _round(years) if years >= 10 else _div(_round(years * 10), 10) return f"{_js_num_str(rounded)} {plural('year', rounded)}" - shown = _div(_round(n * 100), 100) + # a whole count is shown as it is: n * 100 is not exact past 2^53 / 100, and 9007199254740990 came back a day short + shown = n if n.is_integer() else _div(_round(n * 100), 100) return f"{_js_num_str(shown)} {plural(unit, shown)}" diff --git a/tests/test_calendar.py b/tests/test_calendar.py index 46ee732..d6b77dc 100644 --- a/tests/test_calendar.py +++ b/tests/test_calendar.py @@ -392,6 +392,17 @@ def test_surface_helpers() -> None: assert format_duration({"version": 1, "grain": "day", "step_name": "sol"}, 14) == "14 sols" +def test_duration_wrong_kind_step_name_and_whole_counts() -> None: + """A step_name that is not a string reads as absent; a whole count is exact up to the safe integers.""" + day = {"version": 2, "grain": "day"} + assert format_duration({**day, "step_name": 5}, 3) == "3 days" + assert format_duration({**day, "step_name": None}, 1) == "1 day" + assert format_duration({**day, "step_name": ["sol"]}, 2) == "2 days" + assert format_duration(day, 9007199254740990) == "9007199254740990 days" + assert format_duration(day, 9007199254740991) == "9007199254740991 days" + assert format_duration(day, 0.333) == "0.33 days" + + def test_mid_labels_and_month_starts() -> None: """Not in the SDK's tests; the comparison against its built package covers them too.""" assert format_mid_label(KIRROWMOSS, 7603) == "14 Thistlewane 22" From 8b699e16e4cb33c0f18500ac1ff2aabd52113667 Mon Sep 17 00:00:00 2001 From: Titus Date: Fri, 27 Nov 2026 07:41:52 +0100 Subject: [PATCH 2/2] calendar: the step_name comment on its own line, inside ruff's 120 columns Co-Authored-By: Claude Opus 5.5 --- src/onlyworlds/calendar.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/onlyworlds/calendar.py b/src/onlyworlds/calendar.py index 0986a5a..6fb19f9 100644 --- a/src/onlyworlds/calendar.py +++ b/src/onlyworlds/calendar.py @@ -1579,7 +1579,8 @@ def format_duration(cfg: Mapping[str, Any], steps: float) -> str: ``12 days`` in the calendar's word for a step.""" n = abs(_in(steps)) word = _prop(cfg, "step_name") - if not isinstance(word, str): # a step_name that is not a string reads as absent (the profile's rule for an optional key of the wrong kind) + # a step_name that is not a string reads as absent (the profile's rule for an optional key of the wrong kind) + if not isinstance(word, str): word = _prop(cfg, "grain") if _nullish(word): word = "step"