Fix naturalsize() ValueError for custom formats containing text - #367
Open
Sanjays2402 wants to merge 1 commit into
Open
Fix naturalsize() ValueError for custom formats containing text#367Sanjays2402 wants to merge 1 commit into
Sanjays2402 wants to merge 1 commit into
Conversation
naturalsize()'s unit rollover check ran the user-supplied format string through float(), which raises ValueError whenever that format contains text around the numeric conversion (e.g. "Size: %.1f"), a regression from 4.15.0. Compare the rendered mantissa against the rendered base instead, so the carry-over still works and arbitrary formats are accepted again. Closes python-humanize#366
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #366
Changes proposed in this pull request:
naturalsize()'s unit-rollover check ran the user-suppliedformatthroughfloat(), so any format with text around the conversion (e.g."Size: %.1f") raisedValueError— a regression from 4.15.0.1.0 MBcarry-over while accepting arbitrary formats again.tests/test_filesize.py; they fail withValueErrorwithout the fix and pass with it.This change was prepared with AI assistance; the regression test was run locally and fails without the fix.