8000 _codecs: Fix buffer parameters by JelleZijlstra · Pull Request #9003 · python/typeshed · GitHub
[go: up one dir, main page]

Skip to content

_codecs: Fix buffer parameters #9003

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 2 commits into from
Oct 28, 2022
Merged

_codecs: Fix buffer parameters #9003

merged 2 commits into from
Oct 28, 2022

Conversation

JelleZijlstra
Copy link
Member

No description provided.

def charmap_encode(__str: str, __errors: str | None = ..., __mapping: _CharMap | None = ...) -> tuple[bytes, int]: ...
def escape_decode(__data: str | bytes, __errors: str | None = ...) -> tuple[str, int]: ...
def escape_decode(__data: str | ReadableBuffer, __errors: str | None = ...) -> tuple[str, int]: ...
def escape_encode(__data: bytes, __errors: str | None = ...) -> tuple[bytes, int]: ...
Copy link
Member Author

Choose a reason for hiding this comment

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

This one is really just bytes:

>>> _codecs.escape_encode(bytearray(b"x"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: escape_encode() argument 1 must be bytes, not bytearray

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

Copy link
Collaborator
@srittau srittau left a comment

Choose a reason for hiding this comment

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

I've only found this in the Python docs in regards to whether codecs should be able to handle any buffer:

https://docs.python.org/3/library/codecs.html?highlight=codec#codecs.Codec.decode

Codec.decode(input, errors='strict')
[...]
For text encodings and bytes-to-bytes codecs, input must be a bytes object or on 7BA6 e which provides the read-only buffer interface – for example, buffer objects and memory mapped files.

But I guess this kind of implies that generally buffer protocol objects are okay where bytes are allowed.

@srittau srittau merged commit bcd876f into python:master Oct 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0