Skip to content

Releases: underwoo/fsize

v0.6.0

Choose a tag to compare

@underwoo underwoo released this 08 Jul 16:36

What's Changed

Closes the remaining validation gaps from the v0.5.0 code review. Note two intentional behavior changes: string values with units now conflict-check against a prefixed units argument (previously the string silently won), and string parsing is now as permissive as float().

Bug Fixes

  • Bare iB units rejected: FSize(1, "iB") now raises Unknown units: iB — the i marker requires a prefix letter (KiB, MiB, …).
  • units argument always validated: FSize("1 KiB", "bogus") now raises Unknown units: bogus instead of silently ignoring the invalid argument.
  • Units mismatch detection: when the value string carries units that disagree with a prefixed units argument, construction raises a dedicated error, e.g. FSize("1 KiB", "MB")units mismatch: value has 'KiB' but units argument is 'MB'. Matching units (case-insensitive) are accepted, and the default bare "B" argument never conflicts. This replaces the previous behavior where the string's bare B silently overrode the argument (FSize("1024 B", "MB") returned 1024; it now raises).
  • String parsing matches float(): string values now accept anything float() accepts — scientific notation ("1e6", "1.5e3 KiB"), trailing decimal point ("1."), underscores ("1_000"), and leading whitespace (" 1.5 MiB").
  • Clearer error messages: negative strings ("-1", "-1 KiB") now report FSize cannot be negative and non-finite strings ("inf", "nan") report FSize must be finite, instead of the generic conversion error.

Chores

  • Version bump to 0.6.0

Full Changelog: v0.5.0...v0.6.0

v0.5.0

Choose a tag to compare

@underwoo underwoo released this 08 Jul 16:10

What's Changed

Five edge-case bugs found in a code review of FSize.__new__ and __format__.

Bug Fixes

  • Bytes in format spec: format(x, "B") (also "b" and "iB") now formats the value in bytes; previously the B was silently ignored and the value was formatted in K. A spec with no unit letter still defaults to K.
  • Non-finite values: FSize(float("inf")) and FSize(float("nan")) now raise ValueError at construction instead of producing values that crash __format__ with OverflowError.
  • Width precision: a field wider than the value's significant digits (e.g. format(FSize(1.1, "KiB"), "20K")) now pads instead of exposing floating-point noise like 1.1000000000000000888.
  • Scientific notation on round-up: values that round up to the next power of 10 at the chosen precision (e.g. format(FSize(9999999.99 * 1024), "K")) now print 10000000 instead of 1e+07.
  • Copy construction: FSize(FSize(1, "KB")) now preserves the source's decimal/binary conversion mode instead of resetting to binary.

Chores

  • Version bump to 0.5.0

Full Changelog: v0.4.0...v0.5.0

v0.4.0

Choose a tag to compare

@underwoo underwoo released this 22 Jun 21:44

What's Changed

All six GitHub issues resolved since v0.3.0.

Bug Fixes

  • Empty format spec (#3): format(x, "") now returns str(x) when format_spec is empty (PR #7)
  • Bare "B" unit (#2): A unit string like "B" in the format spec now correctly overrides the units= constructor parameter (PR #9)
  • Scientific notation (#1): Exact powers of 10 (e.g. format(FSize(10*1024), "K")) no longer produce "1e+01" — use floor(log10(n)) + 1 instead of ceil(log10(n)) for precision calculation (PR #12)

Refactors

  • Unit dispatch (#4, #5): Replaced the 6-branch if/elif chain with a single _UNIT_POWERS dict lookup, eliminating duplicate mapping and dead initialization in __format__ (PR #10)
  • match.group (#6): match.group() called once per parsed field instead of twice (PR #11)

Chores

  • Version bump to 0.4.0

Full Changelog: v0.3.0...v0.4.0

v0.3.0

Choose a tag to compare

@underwoo underwoo released this 28 May 16:04

What's Changed

  • Fix __format__ for zero-valued FSize instances
  • Strengthen tests for zero formatting and invalid format error messages
  • Require all CI checks (pytest, mypy, pylint) to pass before committing
  • Apply code review fixes and cleanups

v0.2.0

Choose a tag to compare

@underwoo underwoo released this 27 May 23:52