Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bytesize #977

Merged
merged 13 commits into from Nov 9, 2019
Merged

Bytesize #977

merged 13 commits into from Nov 9, 2019

Conversation

@dgasmith
Copy link
Contributor

dgasmith commented Nov 7, 2019

Change Summary

Adds a ByteSize object to automatically cast common byte string to bytes.

Related issue number

#971

Checklist

  • Unit tests for the changes exist
  • Tests pass on CI and coverage remains at 100%
  • Documentation reflects the changes where applicable
  • changes/<pull request or issue id>-<github username>.md file added describing change
    (see changes/README.md for details)
@codecov

This comment has been minimized.

Copy link

codecov bot commented Nov 7, 2019

Codecov Report

Merging #977 into master will not change coverage.
The diff coverage is 100%.

@@          Coverage Diff          @@
##           master   #977   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          19     19           
  Lines        3237   3297   +60     
  Branches      642    654   +12     
=====================================
+ Hits         3237   3297   +60
Impacted Files Coverage Δ
pydantic/types.py 100% <100%> (ø) ⬆️
pydantic/errors.py 100% <100%> (ø) ⬆️
pydantic/dataclasses.py 100% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4218ff7...f5c82b4. Read the comment docs.

docs/usage/types.md Show resolved Hide resolved
@@ -499,3 +501,11 @@ class LuhnValidationError(PydanticValueError):
class InvalidLengthForBrand(PydanticValueError):
code = 'payment_card_number.invalid_length_for_brand'
msg_template = 'Length for a {brand} card must be {required_length}'


class InvalidByteString(PydanticValueError):

This comment has been minimized.

Copy link
@samuelcolvin

samuelcolvin Nov 8, 2019

Owner
Suggested change
class InvalidByteString(PydanticValueError):
class InvalidByteSize(PydanticValueError):

and below

pydantic/types.py Show resolved Hide resolved
pydantic/types.py Outdated Show resolved Hide resolved
pydantic/types.py Outdated Show resolved Hide resolved
pydantic/types.py Outdated Show resolved Hide resolved
unit = "B"

try:
unit_mult = BYTE_SIZES[unit.lower()]

This comment has been minimized.

Copy link
@samuelcolvin

samuelcolvin Nov 8, 2019

Owner

are we sure about the lower here?

1b generally means "1 bit" not "1 byte".

This comment has been minimized.

Copy link
@dgasmith

dgasmith Nov 8, 2019

Author Contributor

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.

This comment has been minimized.

Copy link
@samuelcolvin

samuelcolvin Nov 8, 2019

Owner

Let's keep it like this. It's called ByteSize after call.

But please add an info section to the docs explaining this.

This comment has been minimized.

Copy link
@dgasmith

dgasmith Nov 8, 2019

Author Contributor

Added.

pydantic/types.py Outdated Show resolved Hide resolved
pydantic/types.py Outdated Show resolved Hide resolved
pydantic/types.py Outdated Show resolved Hide resolved
pydantic/types.py Outdated Show resolved Hide resolved
dgasmith and others added 8 commits Nov 7, 2019
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
Co-Authored-By: Samuel Colvin <samcolvin@gmail.com>
@dgasmith dgasmith force-pushed the dgasmith:bytesize branch from 7748d1c to 0e7fe57 Nov 8, 2019
dgasmith added 2 commits Nov 8, 2019
@samuelcolvin

This comment has been minimized.

Copy link
Owner

samuelcolvin commented Nov 8, 2019

can you fix tests please. I think it's just double quotes.

Best to run make test before pushing.

docs/usage/types.md Outdated Show resolved Hide resolved
docs/examples/types_bytesize.py Outdated Show resolved Hide resolved
pydantic/types.py Outdated Show resolved Hide resolved
pydantic/types.py Outdated Show resolved Hide resolved
'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})

This comment has been minimized.

Copy link
@samuelcolvin

samuelcolvin Nov 8, 2019

Owner

maybe add a test for this case.

@dgasmith dgasmith force-pushed the dgasmith:bytesize branch 2 times, most recently from 6e98bb7 to 9d2c3be Nov 8, 2019
@dgasmith dgasmith force-pushed the dgasmith:bytesize branch from 9d2c3be to 75b60d0 Nov 8, 2019
@samuelcolvin samuelcolvin merged commit b92e74d into samuelcolvin:master Nov 9, 2019
11 checks passed
11 checks passed
Header rules No header rules processed
Details
Pages changed 6 new files uploaded
Details
Redirect rules No redirect rules processed
Details
Mixed content No mixed content detected
Details
codecov/project 100% (+0%) compared to 4218ff7
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
deploy/netlify Deploy preview ready!
Details
samuelcolvin.pydantic Build #20191109.2 succeeded
Details
samuelcolvin.pydantic (Job Python36) Job Python36 succeeded
Details
samuelcolvin.pydantic (Job Python37) Job Python37 succeeded
Details
samuelcolvin.pydantic (Job Python38) Job Python38 succeeded
Details
@samuelcolvin

This comment has been minimized.

Copy link
Owner

samuelcolvin commented Nov 9, 2019

thanks so much.

@samuelcolvin

This comment has been minimized.

Copy link
Owner

samuelcolvin commented Nov 9, 2019

ID of this matches my favourite xkcd

@dgasmith dgasmith deleted the dgasmith:bytesize branch Nov 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.