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

MAINT: Amend byte cache #2730

Closed
wants to merge 3 commits into from
Closed

MAINT: Amend byte cache #2730

wants to merge 3 commits into from

Conversation

j-t-1
Copy link
Contributor

@j-t-1 j-t-1 commented Jun 28, 2024

Cache string to byte conversions when the string length is greater than one.
#2726

Cache string to byte conversions when the string length is greater than one.
@stefan6419846 stefan6419846 added the needs-discussion The PR/issue needs more discussion before we can continue label Jun 28, 2024
Copy link

codecov bot commented Jun 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.14%. Comparing base (c96d01c) to head (e3136a6).
Report is 73 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2730   +/-   ##
=======================================
  Coverage   95.14%   95.14%           
=======================================
  Files          51       51           
  Lines        8547     8547           
  Branches     1703     1703           
=======================================
  Hits         8132     8132           
  Misses        261      261           
  Partials      154      154           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@stefan6419846
Copy link
Collaborator

I am not sure if this really makes sense or what the original intent of the old implementation has been. Until this is more clear (see my comment in #2726), I recommend against merging this.

@j-t-1
Copy link
Contributor Author

j-t-1 commented Jul 8, 2024

@pytest.mark.parametrize(
    ("input_str", "expected"),
    [
        ("foo", b"foo"),
        ("😀", "😀".encode()),
        ("‰", "‰".encode()),
        ("▷", "▷".encode()),
        ("世", "世".encode()),
        # A multi-character string example with non-latin-1 characters:
        ("😀😃", "😀😃".encode()),
    ],
)
def test_b(input_str: str, expected: str):
    assert pypdf._utils.b_(input_str) == expected

Should this be:

def test_b(input_str: str, expected: bytes):
    assert pypdf._utils.b_(input_str) == expected

@stefan6419846
Copy link
Collaborator

Isn't your new code the same? If you are referring to the decorator - no, this cannot be removed. This defines the parameters/sub-tests to use for the test.

@j-t-1
Copy link
Contributor Author

j-t-1 commented Jul 8, 2024

My comment could have been better. The change is to the type of the second argument from str to bytes (keeping the decorator).

@stefan6419846
Copy link
Collaborator

Yes, the expected parameter should be bytes, as we are encoding the strings here.

@j-t-1
Copy link
Contributor Author

j-t-1 commented Jul 8, 2024

The caching of the existing function is maybe deliberate.

@j-t-1 j-t-1 closed this Jul 8, 2024
@j-t-1 j-t-1 deleted the b_ branch July 9, 2024 07:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-discussion The PR/issue needs more discussion before we can continue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants