Skip to content

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Toshaksha
Copy link

@Toshaksha Toshaksha commented Jul 5, 2025

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.

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

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

Choose a reason for hiding this comment

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

Where is errors='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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review docs Documentation in the Doc dir needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes skip news
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

Write documentation for codecs.escape_encode() and codecs.escape_decode()
3 participants