-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Python 3.14: PEP-784 compression.zstd #14129
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
base: main
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@emmatyping: if you want to give try this out, or simply comment on the use of |
I think we should type that it accepts |
stdlib/_zstd.pyi
Outdated
def __init__( | ||
self, level: int | None = ..., options: _OptionsCompress | None = ..., zstd_dict: ZstdDict | None = ... | ||
) -> None: ... | ||
def compress(self, /, data: ReadableBuffer, mode: Literal[0, 1, 2] = ...) -> bytes: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it might be useful to express these in terms of the ZstdCompressor
attributes. It will make it easier to understand I think? If you think it makes the signature too busy then I suppose it is fine as is, but I want discourage passing bare integers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(similarly it'd be good to do the same below with the ZstdFile methods)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the below is invalid:
Literal[CONTINUE, FLUSH_BLOCK, FLUSH_FRAME]
But maybe I can try to do something like the following:
_ZstdCompressorContinueType = Literal[0]
_ZstdCompressorFlushBlockType = Literal[1]
_ZstdCompressorFlushFrameType = Literal[2]
@final
class ZstdCompressor:
CONTINUE: Final[_ZstdCompressorContinueType] = 0
FLUSH_BLOCK: Final[_ZstdCompressorFlushBlockType] = 1
FLUSH_FRAME: Final[_ZstdCompressorFlushFrameType] = 2
def compress(self, /, data: ReadableBuffer, mode: _ZstdCompressorContinueType | _ZstdCompressorFlushBlockType | _ZstdCompressorFlushFrameType = ...) -> bytes: ...
Is it what you meant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't you do CONTINUE | FLUSH_BLOCK | FLUSH_FRAME
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's possible (playground)
main.py:8: error: Variable "__main__.ZstdCompressor.CONTINUE" is not valid as a type [valid-type]
main.py:8: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
main.py:8: error: Variable "__main__.ZstdCompressor.FLUSH_BLOCK" is not valid as a type [valid-type]
main.py:8: error: Variable "__main__.ZstdCompressor.FLUSH_FRAME" is not valid as a type [valid-type]
I will go ahead and make the changes of defining the Literal
once and reusing them afterwards.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I think that is fine then.
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Second PR about PEP-784 in stdlib (first PR):
_zstd
compression.zstd
The CI current failures are due to the use of 3.14 beta1; to address this:
3.14
branch)stubtest
errors) - expected May 26th