Releases: underwoo/fsize
Releases · underwoo/fsize
Release list
v0.6.0
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
iBunits rejected:FSize(1, "iB")now raisesUnknown units: iB— theimarker requires a prefix letter (KiB,MiB, …). unitsargument always validated:FSize("1 KiB", "bogus")now raisesUnknown units: bogusinstead of silently ignoring the invalid argument.- Units mismatch detection: when the value string carries units that disagree with a prefixed
unitsargument, 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 bareBsilently overrode the argument (FSize("1024 B", "MB")returned 1024; it now raises). - String parsing matches
float(): string values now accept anythingfloat()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 reportFSize cannot be negativeand non-finite strings ("inf","nan") reportFSize 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
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 theBwas 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"))andFSize(float("nan"))now raiseValueErrorat construction instead of producing values that crash__format__withOverflowError. - 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 like1.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 print10000000instead of1e+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
What's Changed
All six GitHub issues resolved since v0.3.0.
Bug Fixes
- Empty format spec (#3):
format(x, "")now returnsstr(x)when format_spec is empty (PR #7) - Bare "B" unit (#2): A unit string like
"B"in the format spec now correctly overrides theunits=constructor parameter (PR #9) - Scientific notation (#1): Exact powers of 10 (e.g.
format(FSize(10*1024), "K")) no longer produce"1e+01"— usefloor(log10(n)) + 1instead ofceil(log10(n))for precision calculation (PR #12)
Refactors
- Unit dispatch (#4, #5): Replaced the 6-branch if/elif chain with a single
_UNIT_POWERSdict 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
v0.2.0
Full Changelog: https://github.com/underwoo/fsize/commits/v0.2.0