Skip to content

codecs: improve bytes handling #9065

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

Closed
wants to merge 2 commits into from
Closed

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Nov 2, 2022

Source code: https://github.com/python/cpython/blob/0689b99bb8c4f6058af43a52effaa8a25609dbed/Lib/codecs.py#L312-L322

You can use + with bytes:

>>> b'' + bytearray()
b''
>>> b'' + memoryview(b'a')
b'a'
>>> b'' + memoryview(b'a')
b'a'

>>> import array
>>> b'1' + array.array('b')
b'1'

Refs #9059

@sobolevn
Copy link
Member Author

sobolevn commented Nov 2, 2022

Mypy correctly raises:

 stdlib/io.pyi:193: error: Argument 1 of "decode" is incompatible with supertype "IncrementalDecoder"; supertype defines the argument type as "Union[bytes, Union[bytearray, memoryview, array[Any], mmap, _CData, PickleBuffer]]"

It needs changes from #9059 to be correct.
I will merge these two prs into #9059

@sobolevn sobolevn closed this Nov 2, 2022
@github-actions
Copy link
Contributor

github-actions bot commented Nov 2, 2022

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

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.

1 participant