Bytesize#977
Conversation
Codecov Report
@@ Coverage Diff @@
## master #977 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 19 19
Lines 3237 3297 +60
Branches 642 654 +12
=====================================
+ Hits 3237 3297 +60
Continue to review full report at Codecov.
|
| msg_template = 'Length for a {brand} card must be {required_length}' | ||
|
|
||
|
|
||
| class InvalidByteString(PydanticValueError): |
There was a problem hiding this comment.
| class InvalidByteString(PydanticValueError): | |
| class InvalidByteSize(PydanticValueError): |
and below
| unit = "B" | ||
|
|
||
| try: | ||
| unit_mult = BYTE_SIZES[unit.lower()] |
There was a problem hiding this comment.
are we sure about the lower here?
1b generally means "1 bit" not "1 byte".
There was a problem hiding this comment.
Hard to say, I see it quite a few cases where it is stated as 1gb meaning 1GB, but your bits comment is very valid. I would say casting lower is fine for my domain, but network engineers would likely be less than happy about this.
There was a problem hiding this comment.
Let's keep it like this. It's called ByteSize after call.
But please add an info section to the docs explaining this.
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
|
can you fix tests please. I think it's just double quotes. Best to run |
| 'EiB': 2 ** 60, | ||
| } | ||
| BYTE_SIZES.update({k.lower(): v for k, v in BYTE_SIZES.items()}) | ||
| BYTE_SIZES.update({k.lower()[0]: v for k, v in BYTE_SIZES.items() if "i" not in k}) |
There was a problem hiding this comment.
maybe add a test for this case.
6e98bb7 to
9d2c3be
Compare
|
thanks so much. |
|
ID of this matches my favourite xkcd |
* ByteSize object * Human readable format * Lint, tests, and docs * Update pydantic/errors.py Co-Authored-By: Samuel Colvin <samcolvin@gmail.com> * Update pydantic/types.py Co-Authored-By: Samuel Colvin <samcolvin@gmail.com> * Update pydantic/types.py Co-Authored-By: Samuel Colvin <samcolvin@gmail.com> * Allows human readable decimal descriptor * Review comments * Less verbose testing * ByteSize docs * Reworks valid units * Missing type * tweak tests
Change Summary
Adds a
ByteSizeobject to automatically cast common byte string to bytes.Related issue number
#971
Checklist
changes/<pull request or issue id>-<github username>.mdfile added describing change(see changes/README.md for details)