Kaydet (Commit) 26f1dc60 authored tarafından Batuhan Taşkaya's avatar Batuhan Taşkaya

fix rmod

üst 4c3b7e4d
......@@ -1252,6 +1252,3 @@ attribute.
.. versionchanged:: 3.5
New methods ``__getnewargs__``, ``__rmod__``, ``casefold``,
``format_map``, ``isprintable``, and ``maketrans``.
.. versionchanged:: 3.8
The ``__rmod__`` method is removed.
......@@ -1214,6 +1214,10 @@ class UserString(_collections_abc.Sequence):
__rmul__ = __mul__
def __mod__(self, args):
return self.__class__(self.data % args)
def __rmod__(self, template):
if isinstance(template, str):
return self.__class__(template % self)
return NotImplemented
# the following methods are defined in alphabetical order:
def capitalize(self): return self.__class__(self.data.capitalize())
def casefold(self):
......
......@@ -70,6 +70,11 @@ class TestUserObjects(unittest.TestCase):
obj[123] = "abc"
self._copy_test(obj)
def test_str_rmod(self):
arg = UserString("python")
template = "I love %s"
self.assertEqual(arg.__rmod__(template), "I love python")
self.assertIs(arg.__rmod__(type('Dummy', (), {})), NotImplemented)
################################################################################
### ChainMap (helper class for configparser and the string module)
......
The ``__rmod__`` method of ``collections.UserString`` class is removed.
Fix bug in ``__rmod__`` of ``UserString`` - by Batuhan Taskaya.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment