Download benchmark/python/py-premature-filesize-rollover/reference-solution.patch from RedinGhost/beforedone-paper: direct link, hf CLI and curl.
- Browser
- Download file 1.42 kB
-
https://huggingface.co/datasets/RedinGhost/beforedone-paper/resolve/main/benchmark/python/py-premature-filesize-rollover/reference-solution.patch
- Command line
-
hf download hf://datasets/RedinGhost/beforedone-paper/benchmark/python/py-premature-filesize-rollover/reference-solution.patch
-
curl -L -o reference-solution.patch https://huggingface.co/datasets/RedinGhost/beforedone-paper/resolve/main/benchmark/python/py-premature-filesize-rollover/reference-solution.patch
1.42 kB
| diff --git a/src/humanize/filesize.py b/src/humanize/filesize.py | |
| index fb675fd..cf09f1e 100644 | |
| --- a/src/humanize/filesize.py | |
| +++ b/src/humanize/filesize.py | |
| def naturalsize( | |
| binary: bool = False, | |
| gnu: bool = False, | |
| format: str = "%.1f", | |
| + *, | |
| + rollover: bool = True, | |
| ) -> str: | |
| """Format a number of bytes like a human-readable filesize (e.g. 10 kB). | |
| def naturalsize( | |
| gnu (bool): If `True`, the binary argument is ignored and GNU-style | |
| (`ls -sh` style) prefixes are used (K, M) with the 2**10 definition. | |
| format (str): Custom formatter. | |
| + rollover (bool): Promote a rounded mantissa to the next suffix when available. | |
| Returns: | |
| str: Human readable representation of a filesize. | |
| def naturalsize( | |
| # mantissa afterward; rounding can push it up to `base` (e.g. 999999 is | |
| # 999.999 kB, which formats to "1000.0 kB"). When that happens and a larger | |
| # suffix is available, step up one suffix so the result reads "1.0 MB". | |
| - if exp < len(suffix) and abs(float(format % (abs_bytes / (base**exp)))) >= base: | |
| + if ( | |
| + rollover | |
| + and exp < len(suffix) | |
| + and abs(float(format % (abs_bytes / (base**exp)))) >= base | |
| + ): | |
| exp += 1 | |
| space = "" if gnu else " " | |
| ret: str = format % (bytes_ / (base**exp)) + space + _(suffix[exp - 1]) | |