Skip to content

gh-132983: Split _zstd_set_c_parameters #133921

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

Merged
merged 17 commits into from
May 28, 2025
Merged

Conversation

AA-Turner
Copy link
Member

@AA-Turner AA-Turner commented May 12, 2025

The current _zstd_set_c_parameters shares little between the two possible (int or dict) paths. By splitting the function, we can now use the Py_ssize_t AC converter.

One slight change worth noting is that the constructor won't raise an error when level is $-2^{63}$ but will just silently use the default. cc @erlend-aasland if there's a better method/sentinel we can use in the clinic to detect if the value has been set or not.

>>> _zstd.ZstdCompressor(level=-(1<<63)+1)
Traceback (most recent call last):
  File "<python-input-17>", line 1, in <module>
    _zstd.ZstdCompressor(level=-(1<<63)+1)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
ValueError: compression level -9223372036854775807 not in valid range -131072 <= level <= 22.
>>> _zstd.ZstdCompressor(level=-(1<<63))
<compression.zstd.ZstdCompressor object at 0x7f61875b2210>

I also think it might be worth considering removing the level XOR options check, as we could adopt the rule that a compression level set in an options dict overrides the level parameter. I can see reasonable arguments to keep the status quo, however, so I've not done this yet.

A

cc @Rogdham

@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented May 12, 2025

if there's a better method/sentinel we can use in the clinic to detect if the value has been set or not

No, there is not. You cannot distinguish the passed value from the default value. It is better to not using Argument Clinic for conversion of this parameter.

BTW, Py_ssize_t is the same as int on 32-bit platforms, so there is no good reason to use it here.

@emmatyping

This comment was marked as resolved.

@serhiy-storchaka

This comment was marked as resolved.

@emmatyping

This comment was marked as outdated.

@emmatyping

This comment was marked as outdated.

@bedevere-app
Copy link

bedevere-app bot commented May 24, 2025

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

Copy link
Member

@emmatyping emmatyping left a comment

Choose a reason for hiding this comment

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

A few suggestions for wording of error messages, but I think otherwise this looks great. Thank you for refactoring this!

Copy link
Member

@emmatyping emmatyping left a comment

Choose a reason for hiding this comment

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

Thanks, this is a great refactor!

@AA-Turner AA-Turner enabled auto-merge (squash) May 28, 2025 12:43
Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

I am not sure about term "illegal", this is a question to native speakers, but the rest LGTM. Thank you.

AA-Turner and others added 3 commits May 28, 2025 14:12
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@emmatyping
Copy link
Member

I am not sure about term "illegal"

It's not wrong, but perhaps invalid is better?

@AA-Turner AA-Turner merged commit 11f7a93 into python:main May 28, 2025
38 checks passed
@miss-islington-app
Copy link

Thanks @AA-Turner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 28, 2025
(cherry picked from commit 11f7a93)

Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
@bedevere-app
Copy link

bedevere-app bot commented May 28, 2025

GH-134838 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label May 28, 2025
AA-Turner added a commit that referenced this pull request May 28, 2025
gh-132983: Split ``_zstd_set_c_parameters`` (GH-133921)
(cherry picked from commit 11f7a93)

Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants