[proxy] github.com← back | site home | direct (HTTPS) ↗ | proxy home | ◑ dark◐ light

bpo-36582: Make collections.UserString.encode() return bytes, not str by asqui · Pull Request #13138 · python/cpython

asqui

In Python 2 a subclass of UserString would return an instance of that
subclass from encode(). This is invalid in Python 3, where the result of
encode() should always be `bytes`.

Also:
* Collapse the 3 code paths in UserString.encode() into a single path by
  lifting the underlying str.encode() defaults into the method signature

* Test to ensure that utf-8/strict are used as defaults
* Use the self.check*() methods instead of assertEqual() in tests
  (This makes test_encode() more portable; it is eligible for promotion
   to MixinStrUnicodeUserStringTest, as it is a valid test case for
   `str` too.)

NB: Minor backward compatibility break for any existing code that
    specifies encoding='' (or any other 'Falsy' value)

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request

Aug 28, 2019
…pythonGH-13138)

(cherry picked from commit 2a16eea)

Co-authored-by: Daniel Fortunov <asqui@users.noreply.github.com>

rhettinger pushed a commit that referenced this pull request

Aug 28, 2019
…GH-13138) (GH-15557)

(cherry picked from commit 2a16eea)

Co-authored-by: Daniel Fortunov <asqui@users.noreply.github.com>

lisroach pushed a commit to lisroach/cpython that referenced this pull request

Sep 10, 2019

DinoV pushed a commit to DinoV/cpython that referenced this pull request

Jan 14, 2020

asqui deleted the UserString-encode-fix-bpo-36582 branch

June 6, 2020 22:56

websurfer5 pushed a commit to websurfer5/cpython that referenced this pull request

Jul 20, 2020