This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients jcgoble3, rhettinger, serhiy.storchaka, xiang.zhang
Date 2016-03-06.14:10:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1457273409.14.0.335788760038.issue25652@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2016-03-06 14:10:09serhiy.storchakasetrecipients: + serhiy.storchaka, rhettinger, xiang.zhang, jcgoble3
2016-03-06 14:10:09serhiy.storchakasetmessageid: <1457273409.14.0.335788760038.issue25652@psf.upfronthosting.co.za>
2016-03-06 14:10:09serhiy.storchakalinkissue25652 messages
2016-03-06 14:10:08serhiy.storchakacreate