Message261251
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. |
|
Date |
User |
Action |
Args |
2016-03-06 14:10:09 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, rhettinger, xiang.zhang, jcgoble3 |
2016-03-06 14:10:09 | serhiy.storchaka | set | messageid: <1457273409.14.0.335788760038.issue25652@psf.upfronthosting.co.za> |
2016-03-06 14:10:09 | serhiy.storchaka | link | issue25652 messages |
2016-03-06 14:10:08 | serhiy.storchaka | create | |
|