Repository navigation
Conversation
|
Hi! Thank you for reviewing my PR. I noticed that it is still waiting for a required review. Could a maintainer please review my changes and approve the pending workflow runs? Thank you! |
jgohel9902
left a comment
There was a problem hiding this comment.
Thanks for the fix. The UTF-8 approach is correct and backward compatible: I compared it with zlib.adler32(text.encode()) on several non-ASCII strings and everything matched. The main request is to add non-ASCII doctests so the bug stays fixed.
| Iterates and evaluates a new value for each character | ||
| Iterates over the UTF-8 bytes of the input text. | ||
|
|
||
| >>> adler32('Algorithms') |
There was a problem hiding this comment.
The fix is correct: I compared it with zlib.adler32(text.encode()) on "€100", "héllo", "日本語" and an emoji, and all matched. But the doctests only cover ASCII, so nothing would catch this bug again. Please add non-ASCII doctests with the literal expected values, e.g.:
>>> adler32('€100')
196018850
>>> adler32('héllo')
192152348
>>> adler32('日本語')
556009089
You could also compare against zlib: >>> import zlib then >>> adler32('€100') == zlib.adler32('€100'.encode()), which shows the property being fixed.
| b = 0 | ||
| for plain_chr in plain_text: | ||
| a = (a + ord(plain_chr)) % MOD_ADLER | ||
| for plain_byte in plain_text.encode("utf-8"): |
There was a problem hiding this comment.
Looks good: encode() is evaluated once before the loop, and UTF-8 matches what zlib.adler32 gets when callers pass text.encode(). One suggestion: say in the docstring that the checksum is over the UTF-8 bytes, so non-ASCII results match zlib. That is the behaviour change, so documenting it helps. Line 17 already says "UTF-8 bytes", which is a good start.
| @@ -14,7 +14,7 @@ | |||
| def adler32(plain_text: str) -> int: | |||
There was a problem hiding this comment.
Optional: there is another open PR for the same issue that changes the signature to bytes (this one keeps str and is backward compatible). The two overlap, so it may be worth coordinating with the maintainers, so only one is merged. This approach avoids breaking callers that pass strings, which I'd consider a plus.
Describe your change
Checklist
Summary
Fixes #15635
Testing