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-136278: Document codecs.escape_encode() and codecs.escape_decode()#136314

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

Open
Toshaksha wants to merge4 commits intopython:main
base:main
Choose a base branch
Loading
fromToshaksha:doc-escape-codec-update

Conversation

Toshaksha
Copy link

@ToshakshaToshaksha commentedJul 5, 2025
edited by hugovk
Loading

This PR adds documentation for the functions codecs.escape_encode() and codecs.escape_decode(), which provide a way to encode and decode byte sequences using escape sequences, similar to how repr(bytes) works.

These APIs are primarily used by the pickle module for handling escaped byte sequences safely.

The documentation includes function signatures, a usage example, and background information referencing the previous usage in Python 2's string_escape codec and considerations for reviving this as bytes_escape.

Closes:#136278


📚 Documentation preview 📚:https://cpython-previews--136314.org.readthedocs.build/

@Toshaksha
Copy link
Author

Hi@StanFromIreland,

Thanks for the feedback and guidance throughout this process!
I have updated the documentation for codecs.escape_encode() and codecs.escape_decode() following the devguide and integrated it into the binary transforms section as suggested.
Please let me know if there are any further changes needed or if I missed anything.

Looking forward to your review!

Best regards,
Toshaksha

@StanFromIreland
Copy link
Member

Hello, in the future please reuse prs, it creates clutter otherwise. I will review later.

@Toshaksha
Copy link
Author

Thanks, noted! I'll make sure to reuse PRs going forward.

@hugovkhugovk added needs backport to 3.13bugs and security fixes needs backport to 3.14bugs and security fixes labelsJul 5, 2025
| zlib_codec | zip, zlib | Compress the operand using | :meth:`zlib.compress` / |
| | | gzip. | :meth:`zlib.decompress` |
+----------------------+------------------+------------------------------+------------------------------+

.. function:: codecs.escape_encode(input, errors='strict')

Choose a reason for hiding this comment

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

Where iserrors='strict' from?

errors: str(accept={str, NoneType}) = None

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for catching that!
I've updated the function signature to use errors=None in accordance with the actual default in _codecsmodule.c.
Let me know if there's anything else you'd like me to adjust. Appreciate your time and feedback!

| | | sequences using escape | / |
| | | sequences, similar to | :func:`codecs.escape_decode` |
| | | :func:`repr` of bytes. | |
+----------------------+------------------+------------------------------+------------------------------+
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is correct. The codec itself (string_escape) was removed after the transition to Python 3. There is noescape_codec to be documented, only the functions which could be used to create a newbytes_escape codec, but that's probably for a separate issue to take care of.

| zlib_codec | zip, zlib | Compress the operand using | :meth:`zlib.compress` / |
| | | gzip. | :meth:`zlib.decompress` |
+----------------------+------------------+------------------------------+------------------------------+

.. function:: codecs.escape_encode(input, errors=None)
Copy link
Member

Choose a reason for hiding this comment

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

Please move this section below the table and its notes.

It may be good to also be good to put these function definitions into a section "Standalone Codec Functions", or something like that, to make it clear that the functions exist without a codec (at the moment) and perhaps with an explanation why this is.

Encode *input* using escape sequences. Similar to how :func:`repr` on bytes
produces escaped byte values. Returns a tuple of the encoded bytes and
the length consumed.

Copy link
Member

Choose a reason for hiding this comment

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

We should document thatinput needs to be a bytes object.


Decode *input* from escape sequences back to the original bytes.
Returns a tuple of the decoded bytes and the length consumed.

Copy link
Member

Choose a reason for hiding this comment

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

We should document thatinput needs to be a bytes or buffer compatible object.

@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.

@Toshaksha
Copy link
Author

I have made the requested changes; please review again.

@bedevere-app
Copy link

Thanks for making the requested changes!

@malemburg: please review the changes made to this pull request.

@bedevere-appbedevere-appbot requested a review frommalemburgJuly 8, 2025 05:17
@ToshakshaToshakshaforce-pushed thedoc-escape-codec-update branch froma7553c6 to4b26d7dCompareJuly 12, 2025 05:09
@Toshaksha
Copy link
Author

Hi@malemburg ,
I’ve addressed all requested changes and pushed updates. Please let me know if anything else is needed.
Thanks!

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

@StanFromIrelandStanFromIrelandStanFromIreland left review comments

@malemburgmalemburgAwaiting requested review from malemburg

Assignees
No one assigned
Labels
awaiting change reviewdocsDocumentation in the Doc dirneeds backport to 3.13bugs and security fixesneeds backport to 3.14bugs and security fixesskip news
Projects
Status: Todo
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Write documentation for codecs.escape_encode() and codecs.escape_decode()
4 participants
@Toshaksha@StanFromIreland@malemburg@hugovk

[8]ページ先頭

©2009-2025 Movatter.jp