cpython: c06b2480766d (original) (raw)
Mercurial > cpython
changeset 96222:c06b2480766d
Issue 22189: Add missing methods to UserString
Raymond Hettinger python@rcn.com | |
---|---|
date | Fri, 22 May 2015 16:56:32 -0700 |
parents | ecde84db7022 |
children | 830bcf4fb29b |
files | Lib/collections/__init__.py Lib/test/test_collections.py Misc/NEWS |
diffstat | 3 files changed, 37 insertions(+), 2 deletions(-)[+] [-] Lib/collections/__init__.py 10 Lib/test/test_collections.py 25 Misc/NEWS 4 |
line wrap: on
line diff
--- a/Lib/collections/init.py +++ b/Lib/collections/init.py @@ -1060,6 +1060,8 @@ class UserString(Sequence): def float(self): return float(self.data) def complex(self): return complex(self.data) def hash(self): return hash(self.data)
def eq(self, string): if isinstance(string, UserString): @@ -1104,9 +1106,13 @@ class UserString(Sequence): rmul = mul def mod(self, args): return self.class(self.data % args)
# the following methods are defined in alphabetical order: def capitalize(self): return self.class(self.data.capitalize())
- def casefold(self):
def center(self, width, *args): return self.class(self.data.center(width, *args)) def count(self, sub, start=0, end=_sys.maxsize): @@ -1129,6 +1135,8 @@ class UserString(Sequence): return self.data.find(sub, start, end) def format(self, *args, **kwds): return self.data.format(*args, **kwds)return self.__class__(self.data.casefold())[](#l1.22)
- def format_map(self, mapping):
def index(self, sub, start=0, end=_sys.maxsize): return self.data.index(sub, start, end) def isalpha(self): return self.data.isalpha() @@ -1138,6 +1146,7 @@ class UserString(Sequence): def isidentifier(self): return self.data.isidentifier() def islower(self): return self.data.islower() def isnumeric(self): return self.data.isnumeric()return self.data.format_map(mapping)[](#l1.31)
- def isprintable(self): return self.data.isprintable() def isspace(self): return self.data.isspace() def istitle(self): return self.data.istitle() def isupper(self): return self.data.isupper() @@ -1146,6 +1155,7 @@ class UserString(Sequence): return self.class(self.data.ljust(width, *args)) def lower(self): return self.class(self.data.lower()) def lstrip(self, chars=None): return self.class(self.data.lstrip(chars))
- maketrans = str.maketrans def partition(self, sep): return self.data.partition(sep) def replace(self, old, new, maxsplit=-1):
--- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -12,7 +12,7 @@ import keyword import re import sys import types -from collections import UserDict +from collections import UserDict, UserString, UserList from collections import ChainMap from collections import deque from collections.abc import Awaitable, Coroutine, AsyncIterator, AsyncIterable @@ -24,6 +24,26 @@ from collections.abc import Sequence, Mu from collections.abc import ByteString +class TestUserObjects(unittest.TestCase):
- def _superset_test(self, a, b):
self.assertGreaterEqual([](#l2.18)
set(dir(a)),[](#l2.19)
set(dir(b)),[](#l2.20)
'{a} should have all the methods of {b}'.format([](#l2.21)
a=a.__name__,[](#l2.22)
b=b.__name__,[](#l2.23)
),[](#l2.24)
)[](#l2.25)
- def test_str_protocol(self):
self._superset_test(UserString, str)[](#l2.27)
+ + ################################################################################
ChainMap (helper class for configparser and the string module)
################################################################################ @@ -1848,7 +1868,8 @@ def test_main(verbose=None): NamedTupleDocs = doctest.DocTestSuite(module=collections) test_classes = [TestNamedTuple, NamedTupleDocs, TestOneTrickPonyABCs, TestCollectionABCs, TestCounter, TestChainMap,
TestOrderedDict, GeneralMappingTests, SubclassMappingTests][](#l2.43)
TestOrderedDict, GeneralMappingTests, SubclassMappingTests,[](#l2.44)
support.run_unittest(*test_classes) support.run_doctest(collections, verbose)TestUserObjects][](#l2.45)