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

add bytes*.fill() helper #761

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft

add bytes*.fill() helper #761

wants to merge 5 commits into from

Conversation

altendky
Copy link
Contributor

No description provided.

@@ -78,6 +79,27 @@ def random(
def secret(cls: Type[_T_SizedBytes]) -> _T_SizedBytes:
return cls.random(r=system_random)

@classmethod
def fill(cls: Type[_T_SizedBytes], blob: bytes, fill: bytes, align: Literal["<", ">"] = ">") -> _T_SizedBytes:
if len(blob) == cls._size:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if len(blob) > cls._size, do we want to truncate and construct cls then too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am tending towards no. It seems like with these classes that truncation would be surprising. I think most use cases for this are tests where you are trying to create unique values. If your blob is too long and is truncated you hazard unexpectedly having multiple of the same value generated.

This isn't meant to be a 'format' level tool, but I will note that format just creates a larger output in this case.

Copy link

coveralls-official bot commented Oct 21, 2024

Pull Request Test Coverage Report for Build 11484936346

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 83.811%

Totals Coverage Status
Change from base Build 11407106182: 0.0%
Covered Lines: 12844
Relevant Lines: 15325

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants