Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-132983: Addcompression.zstd and Python tests#133365

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
AA-Turner merged 56 commits intopython:mainfromemmatyping:3.14-zstd-python-code
May 6, 2025

Conversation

emmatyping
Copy link
Member

@emmatypingemmatyping commentedMay 4, 2025
edited by bedevere-appbot
Loading

The next step to merging the PEP 784 implementation, this PR introducescompression.zstd and tests for the code (which I have been using to test the C code so far).

Since test can be modified post-beta1, I'd like to focus on reviewing the API and Python implementation code. Obviously if there are important tests to add or change, that review would be valuable as well.

@emmatyping
Copy link
MemberAuthor

Also as requested, pinging@Rogdham to review the Python code.

Rogdham reacted with thumbs up emoji

Copy link
Member

@AA-TurnerAA-Turner left a comment

Choose a reason for hiding this comment

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

Review ofLib/compression/zstd/__init__.py

@bedevere-app
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phraseI have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

Copy link
Contributor

@RogdhamRogdham left a comment

Choose a reason for hiding this comment

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

This review is focused on changes frompyzstd.

My main issue isdecompress(compress(b"xxx") + b"yyy") not raising an exception.

Copy link
Contributor

@RogdhamRogdham left a comment
edited
Loading

Choose a reason for hiding this comment

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

These extra comments are due tooptions being passed as positional arguments, but they are passed tolevel parameter instead ofoptions.

I hope I did not miss any 😅

@emmatyping
Copy link
MemberAuthor

I am working on addressing some of the issues which will include the test failures

Copy link
Member

@tomasr8tomasr8 left a comment

Choose a reason for hiding this comment

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

Some nits, nothing major

Copy link
Member

@AA-TurnerAA-Turner left a comment

Choose a reason for hiding this comment

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

Comments on Lib/compression/zstd/_zstdfile.py

@bedevere-app
Copy link

Thanks for making the requested changes!

@AA-Turner: please review the changes made to this pull request.

@bedevere-appbedevere-appbot requested a review fromAA-TurnerMay 5, 2025 23:50
@emmatyping
Copy link
MemberAuthor

emmatyping commentedMay 5, 2025
edited
Loading

FWIW I believe I responded to all reviews, so I will add the buildbots to test this.

@emmatypingemmatyping added the 🔨 test-with-buildbotsTest PR w/ buildbots; report in status section labelMay 5, 2025
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by@emmatyping for commita12a031 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F133365%2Fmerge

If you want to schedule another build, you need to add the🔨 test-with-buildbots label again.

@bedevere-botbedevere-bot removed the 🔨 test-with-buildbotsTest PR w/ buildbots; report in status section labelMay 5, 2025
Python, in general, works on protocols rather than nominal or specific types. I think this check is overly restrictive, with only minor benefit. Users wanting validation can use static type checkers.
@AA-Turner
Copy link
Member

I've pushed a series of commits. Most are explanatory and fairly minor (docstring wording, etc). The one of most note is removing the exact type checks on{C,Dec}ompressionParamater. I think it is overly restrictivie to check the exact type of the enum, and I can't think of a similar example where we do this. Users who want the validation of not conflating compression and decompression can use a staic type checker.

I've pushed this for speed, given time, but if you feel strongly I'm happy for you to revert.

A

@emmatyping
Copy link
MemberAuthor

@AA-Turner The commits look fine other than the last one. It is very important to check the type of a CompressionParameter vs DecompressionParameter because the C enum variants have overlapping values (compression_level == window_log_max)

You can see in the tests this could lead to confusing errors:

Traceback (most recent call last):  File "/home/runner/work/cpython/cpython-ro-srcdir/Lib/test/test_zstd.py", line 1424, in test_init_bad_mode    ZstdFile(io.BytesIO(), 'rb',    ~~~~~~~~^^^^^^^^^^^^^^^^^^^^             options={CompressionParameter.compression_level:5})             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  File "/home/runner/work/cpython/cpython-ro-srcdir/Lib/compression/zstd/_zstdfile.py", line 91, in __init__    raw = _streams.DecompressReader(        self._fp,    ...<3 lines>...        options=options,    )  File "/home/runner/work/cpython/cpython-ro-srcdir/Lib/compression/_common/_streams.py", line 53, in __init__    self._decompressor = self._decomp_factory(**self._decomp_args)                         ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^_zstd.ZstdError: Error when setting zstd decompression parameter "window_log_max", it should 10 <= value <= 31, provided value is 5. (zstd v1.5.5, 64-bit build)

I think I will revert the last commit but keep the others.

This reverts commitbf4b07d.Checking the type of parameters is important to avoid confusing errormessages.
@AA-Turner
Copy link
Member

It is very important to check the type of a CompressionParameter vs DecompressionParameter because the C enum variants have overlapping values

Yes, but I think the risk of this actually hitting users is low? For example, the examplar test failure you provided is very clear:CompressionParameter.compression_level is provided as a key, and the error message says 'Error when setting zstddecompression parameter "window_log_max"' (emph. added).typeshed could annotate theoptions dict asMapping[CompressionParameter, int] which would solve the problem for users of static type checkers. Users who pass nonsense or invalid values will always get undefined behaviour or an error. I think it's better to apply the consenting adults principle here that we see elsewhere in the language. For example, the current code doesn't let me pass anint as the key directly.

I think it's fine to keep for now as we can discuss further and change this during the betas -- this particular item isn't impacted by feature freeze as it's entirely private.

A

emmatyping reacted with thumbs up emoji

@emmatyping
Copy link
MemberAuthor

For example, the examplar test failure you provided is very clear: CompressionParameter.compression_level is provided as a key, and the error message says 'Error when setting zstddecompression parameter "window_log_max"' (emph. added).

I think we view the clarify of the error differently! To me I would expect users to not understand why they are getting an error about a decompression parameter when passing a compression parameter. I think perhaps a compromise would be to check the type if it is a (De)CompressionParameter, but otherwise just allow ints without checking. If you're passing an int, you're on your own!

@emmatyping
Copy link
MemberAuthor

emmatyping commentedMay 6, 2025
edited
Loading

@AA-Turner

For example, the current code doesn't let me pass an int as the key directly.

After writing this:

I think perhaps a compromise would be to check the type if it is a (De)CompressionParameter, but otherwise just allow ints without checking. If you're passing an int, you're on your own!

I just checked and we only check if it isCompressionParameter for decompression, orDecompressionParameter for compression. So the compromise is actually the current behavior. So you can pass an int if you'd like:

>>>from compression.zstdimport*>>> compress(b'testtesttest',options={100:5})b'(\xb5/\xfd \x0ca\x00\x00testtesttest'

Copy link
Member

@AA-TurnerAA-Turner left a comment

Choose a reason for hiding this comment

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

This is mergeable, we can tweak the few remaining items (eg. tarfile, parameter type checks, perhaps tests) after 3.14 beta 1.

Thanks everyone, and especially thank you@Rogdham for the valuable feedback & context frompyzstd.

A

emmatyping, hugovk, and Rogdham reacted with hooray emojiRogdham reacted with heart emoji
@AA-TurnerAA-Turner merged commitc273f59 intopython:mainMay 6, 2025
41 of 42 checks passed
@emmatypingemmatyping deleted the 3.14-zstd-python-code branchMay 6, 2025 00:38
@emmatyping
Copy link
MemberAuthor

emmatyping commentedMay 6, 2025
edited
Loading

Thanks everyone, and especially thank you@Rogdham for the valuable feedback & context from pyzstd.

Hear, hear! And thank you@AA-Turner for your suggestions and contributions! Thank you to all of the reviewers!

hugovk, chris-eibl, and Rogdham reacted with hooray emoji

# All *open() methods are registered here.
OPEN_METH = {
"tar": "taropen", # uncompressed tar
"gz": "gzopen", # gzip compressed tar
"bz2": "bz2open", # bzip2 compressed tar
"xz": "xzopen" # lzma compressed tar
"xz": "xzopen", # lzma compressed tar
"zst": "zstopen" # zstd compressed tar
Copy link
Member

Choose a reason for hiding this comment

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

Trailing comma would have been nice here 🙂
(noting this in case someone does another cleanup PR, but not to request one just for this)

AA-Turner reacted with thumbs up emoji
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

will add this to#133547, thanks!

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@gpsheadgpsheadgpshead left review comments

@merwokmerwokmerwok left review comments

@RogdhamRogdhamRogdham left review comments

@tomasr8tomasr8tomasr8 left review comments

@AA-TurnerAA-TurnerAA-Turner approved these changes

@ethanfurmanethanfurmanAwaiting requested review from ethanfurmanethanfurman is a code owner

@erlend-aaslanderlend-aaslandAwaiting requested review from erlend-aaslanderlend-aasland is a code owner

Assignees
No one assigned
Labels
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

7 participants
@emmatyping@AA-Turner@bedevere-bot@gpshead@merwok@Rogdham@tomasr8

[8]ページ先頭

©2009-2025 Movatter.jp