Skip to content

Fix #239 - #1

Open
codingfrog wants to merge 1 commit into
mainfrom
factory/issue-239
Open

codingfrog wants to merge 1 commit into
mainfrom
factory/issue-239

Conversation

@codingfrog

Copy link
Copy Markdown
Owner

Build ledger: issue python-humanize#239

Issue summary

In 4.12.0, naturalsize changed its output for values below the base unit (1000 or 1024):
naturalsize(1.123456789) returned '1.123456789 Bytes' instead of '1 Bytes'. String input
was also affected ("300" gave '300.0 Bytes'). The cause was the %d to f-string rewrite in python-humanize#226.
Upstream status: the issue is CLOSED. It was fixed on main by 11e62ee (PR python-humanize#240, < base branch)
and a79fb3a (== 1 "Byte" branch). Main has since rewritten this function (math.log, i18n
_("%d Bytes") % int(bytes_), rounding carry), and the current main source already behaves correctly.

Approach

This is now a test-only change. Iter 1 branched from stale a0602c7 and re-implemented the fix (7a324d2),
which conflicted with origin/main and did nothing there (R1.1). In iter 2 the branch was reset to
origin/main (785e5dc), so the source change drops out entirely. I kept only the two regression
cases main does not already cover. Main already has [1.123456789] -> "1 Bytes" and
["1", False, False] -> "1 Byte", so I dropped those duplicates.

Files touched

  • tests/test_filesize.py: 2 new parametrize cases in test_naturalsize, placed after upstream's
    1.123456789 float cases.

Tests added (cases in test_naturalsize)

  • ["300"] -> "300 Bytes": string input below base must not render as 300.0 Bytes.
    The negated re-run checks "-300 Bytes".
  • [300.9, False, True] -> "300B": the GNU path truncates non-integer floats rather than
    rounding them or showing the float repr. The negated re-run checks "-300B".
  • Verified: with the sub-base return temporarily changed back to the 4.12.0 f-string form, both
    new cases fail ('300.0 Bytes', '300.9B'). Restored with git checkout; the source is unchanged.

Gate results (latest)

  • pre-commit: pass (all hooks)
  • pytest: 748 passed, 110 skipped, 0 failed

Decisions and trade-offs

  • I chose a test-only PR over "no PR": both cases guard real paths from the naturalsize output changed between 4.11.0 and 4.12.0 python-humanize/humanize#239 regression
    (string coercion, GNU float) that main's tests don't exercise. If the orchestrator would
    rather not open a PR for a closed issue, dropping this branch is also fine.
  • There was no "fail first" against HEAD, because the fix is already on main. The failing run
    was done against a locally re-introduced regression instead (see Tests added).

Things the next agent must know

  • Branch factory/issue-239 was reset (not rebased) onto origin/main. The old commit 7a324d2 is
    no longer on it.
  • A stray local branch factory/issue-239-iter1-backup (-> 7a324d2) exists. I made it before
    the reset, and deleting it was denied by permissions. It is safe to delete: git branch -D factory/issue-239-iter1-backup.
  • int() truncation in main matches the old %d (e.g. -0.5 -> "0 Bytes", not "-0 Bytes").

Review resolutions

Source Finding Resolution
review.log iter 1 R1.1 BLOCKER: stale branch, conflicts with main, already fixed upstream fixed in 9b928c0: reset onto origin/main, source change dropped, only 2 uncovered test cases kept
review.log iter 1 R1.2 MAJOR: ledger omits upstream status / base / conflict fixed: Issue summary now records the closed issue, the 11e62ee/a79fb3a fixes, the old base a0602c7, the conflict, and the reset decision
review.log iter 1 R1.3 MINOR: "-1 Bytes" should be "-1 Byte" moot: the ["1"] case was dropped (main covers ["1", False, False]). The negation notes are now per-case and accurate
review.log iter 1 R1.4 NIT: place cases next to upstream float cases fixed in 9b928c0: cases go after the 1.123456789 block

Iteration log

  • iter 1: added 4 regression cases, restored integer truncation for sub-base sizes; commit 7a324d2. Blocked only by the environment's yamlfmt binary crash.
  • iter 1 (re-run): checked commit 7a324d2. The 4 new cases fail against a0602c7's filesize.py
    (float repr in the output) and pass with the fix. Re-ran the gates and all pass, yamlfmt
    included. No code changes; HEAD is still 7a324d2.
  • iter 2: reset the branch onto origin/main 785e5dc. Dropped the redundant source fix and the duplicate
    tests, and kept ["300"] and [300.9, False, True] (checked that both fail against the reintroduced
    regression). Gates pass. Commit 9b928c0 (test-only).

… in naturalsize

Issue python-humanize#239 was fixed on main by 11e62ee (python-humanize#240) and a79fb3a. Add the two
sub-base cases those commits don't cover: string input ("300") and a
non-integer float on the GNU path (300.9 -> "300B", truncated). Both
fail against the 4.12.0 f-string regression.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@codingfrog codingfrog left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR review round 1

Test-only change: two new cases in the existing test_naturalsize parametrize table (tests/test_filesize.py:10-94). Codebase fit is good:

  • No new helpers, constants or test functions. The cases extend the existing table rather than adding a parallel test.
  • No duplicates. ["300"] is the string variant of the existing [300] (line 13), in the same way ["1000"] (line 14) and ["1", False, False] (line 72) complement their int forms. [300.9, False, True] checks truncation on the GNU path, which [1.123456789, False, True] (line 80) cannot tell apart from rounding.
  • Placement: next to the upstream float regression cases (lines 77-82) and before the commented rounding-carry block (lines 85-93), so that comment still describes only its own cases.
  • The negated re-run (lines 99-105) handles both new inputs the same way it handles the existing string and float cases ("-300" -> "-300 Bytes", "-300.9" -> "-300B").

Non-blocking notes:

  • The PR title "Fix python-humanize#239" suggests a source fix. python-humanize#239 is already closed and fixed on main (11e62ee, a79fb3a), so something like "Add regression tests for python-humanize#239 (string and GNU float input)" would be more accurate, and the PR should not use a closing keyword.
  • Already on main, not introduced here: the test_args annotation at line 96 (list[int] | list[int | bool]) does not cover the str/float/format-string cases the table holds. Out of scope for this PR.

VERDICT: APPROVE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant