Skip to content

codecs: improve bytes handling - #9065

Closed
sobolevn wants to merge 2 commits into
python:mainfrom
sobolevn:bytes-codecs
Closed

codecs: improve bytes handling#9065
sobolevn wants to merge 2 commits into
python:mainfrom
sobolevn:bytes-codecs

Conversation

@sobolevn

Copy link
Copy Markdown
Member

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'>>>importarray>>>b'1'+array.array('b')
b'1'

Refs #9059

@sobolevn

Copy link
Copy Markdown
MemberAuthor

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

@sobolevnsobolevn closed this Nov 2, 2022
@github-actions

Copy link
Copy Markdown
Contributor

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

Sign up for freeto 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

@sobolevn