Skip to content
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

Bypass the decode() method in bytes subclasses. #219

Merged
merged 4 commits into from
Apr 25, 2018
Merged

Bypass the decode() method in bytes subclasses. #219

merged 4 commits into from
Apr 25, 2018

Conversation

serhiy-storchaka
Copy link
Contributor

The Python and the C implementations produce different results due to using the decode() method.

serhiy-storchaka and others added 4 commits April 25, 2018 19:25
@boussouira
Copy link

This is old, but isn't str(bytes, encoding) is equivalent to bytes.decode(encoding)?

If at least one of encoding or errors is given, object should be a bytes-like object (e.g. bytes or bytearray). In this case, if object is a bytes (or bytearray) object, then str(bytes, encoding, errors) is equivalent to bytes.decode(encoding, errors). Otherwise, the bytes object underlying the buffer object is obtained before calling bytes.decode().

@serhiy-storchaka
Copy link
Contributor Author

It is equivalent if the type of the object is bytes or bytearray. But if it is an instance of a subclass of bytes or bytearray with overridden decode() method, the result of the decode() method can be arbitrary.

@boussouira
Copy link

Make sense, Thank you!

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.

None yet

3 participants