Serhiy Storchaka added the comment:
In normal case there is no infinite recursion in collections.UserString1, since
UserString.__rmod__(S) falls back to S.__mod__(str) or str.__rmod__(S).
>>> S('say %s') % UserString('hello')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/serhiy/py/cpython/Lib/collections/__init__.py", line 1156, in
__rmod__
return self.__class__(format % self.data)
TypeError: unsupported operand type(s) for %: 'S' and 'str'
Infinite recursion is possible if we make recursive UserString (us.data = us),
but in this case we will get infinite recursion in all operations.
collections.UserString1 LGTM at the same degree as UserString.__le__ (it would
be better to handle NotImplemented correctly).
There is yet one consideration. In 2.x UserString simulates both 8-bit and
Unicode strings. In 3.x UserString simulates both str and bytes (except
decode(), bytes formatting, etc). I think it is worth once to make UserString
to support bytes formatting. In this case it would be incorrect to coerce the
template to a regular str.
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue25652>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com