diff options
author | Daniel Fortunov <asqui@users.noreply.github.com> | 2019-08-28 04:38:09 (GMT) |
---|---|---|
committer | Raymond Hettinger <rhettinger@users.noreply.github.com> | 2019-08-28 04:38:09 (GMT) |
commit | 2a16eea71f56c2d8f38c295c8ce71a9a9a140aff (patch) | |
tree | 71726a024fdfef5d79c432687fce143bbf2b41bd /Lib/collections | |
parent | 98d90f745d35d5d07bffcb46788b50e05eea56c6 (diff) | |
download | cpython-2a16eea71f56c2d8f38c295c8ce71a9a9a140aff.zip cpython-2a16eea71f56c2d8f38c295c8ce71a9a9a140aff.tar.gz cpython-2a16eea71f56c2d8f38c295c8ce71a9a9a140aff.tar.bz2 |
bpo-36582: Make collections.UserString.encode() return bytes, not str (GH-13138)
Diffstat (limited to 'Lib/collections')
-rw-r--r-- | Lib/collections/__init__.py | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py index 6a3e599..859b846 100644 --- a/Lib/collections/__init__.py +++ b/Lib/collections/__init__.py @@ -1184,12 +1184,10 @@ class UserString(_collections_abc.Sequence): if isinstance(sub, UserString): sub = sub.data return self.data.count(sub, start, end) - def encode(self, encoding=None, errors=None): # XXX improve this? - if encoding: - if errors: - return self.__class__(self.data.encode(encoding, errors)) - return self.__class__(self.data.encode(encoding)) - return self.__class__(self.data.encode()) + def encode(self, encoding='utf-8', errors='strict'): + encoding = 'utf-8' if encoding is None else encoding + errors = 'strict' if errors is None else errors + return self.data.encode(encoding, errors) def endswith(self, suffix, start=0, end=_sys.maxsize): return self.data.endswith(suffix, start, end) def expandtabs(self, tabsize=8): |