Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Lib/collections/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1214,9 +1214,8 @@ def __mul__(self, n):
__rmul__ = __mul__
def __mod__(self, args):
return self.__class__(self.data % args)
def __rmod__(self, format):
return self.__class__(format % args)

def __rmod__(self, template):
return self.__class__(str(template) % self)
# the following methods are defined in alphabetical order:
def capitalize(self): return self.__class__(self.data.capitalize())
def casefold(self):
Expand Down
12 changes: 12 additions & 0 deletions Lib/test/test_userstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ def checkcall(self, object, methodname, *args):
# we don't fix the arguments, because UserString can't cope with it
getattr(object, methodname)(*args)

def test_rmod(self):
class ustr2(UserString):
pass

class ustr3(ustr2):
def __rmod__(self, other):
return super().__rmod__(other)

fmt2 = ustr2('value is %s')
str3 = ustr3('TEST')
self.assertEqual(fmt2 % str3, 'value is TEST')


if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug in ``__rmod__`` of ``UserString`` - by Batuhan Taskaya.