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.

classification
Title: UserString doesn't combine nicely with strings
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.4
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: Jorge.Cardona, loewis, pschanely, rhettinger, terry.reedy
Priority: normal Keywords:

Created on 2012-11-03 18:13 by Jorge.Cardona, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (6)
msg174658 - (view) Author: Jorge Cardona (Jorge.Cardona) Date: 2012-11-03 18:13
Hi,

I think UserString must play nicely with other standard objects to be useful. For example, right now is not possible to join a list of UserString with a string. 

This shouldn't fail:

   from UserString import UserString
   '.'.join([UserString('some')])

but it fails in 2.7 and it fails too with 3.2 (replacing with collections).

I'm assuming most of the user of UserString, use it as a replacement of a string, and it would be great to actually be able to replace strings passed to thid parties with userstrings. 

I imagine there would be some edge situations harder to resolve, but if someone is just using standard libraries it should be safe to pass a string or an userstring.

Bye.
msg174661 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2012-11-03 18:32
This is not a bug, but a potential new feature. Therefore, it can go only into 3.4 (if at all).
msg174662 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2012-11-03 18:33
If you want a class that behaves like a string object, you should subclass from str.
msg174668 - (view) Author: Jorge Cardona (Jorge.Cardona) Date: 2012-11-03 18:47
mm, I thought that was impossible, and that I should be using UserString
actually. I didn't notice the big warning at the beginning of the section
at the docs.

Sorry, I will change my code.

Thanks.

On Sat, Nov 3, 2012 at 2:33 PM, Martin v. Löwis <report@bugs.python.org>wrote:

>
> Martin v. Löwis added the comment:
>
> If you want a class that behaves like a string object, you should subclass
> from str.
>
> ----------
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue16397>
> _______________________________________
>

-- 
Jorge Eduardo Cardona

jorgeecardona@gmail.com
jorge@cardona.co

cardona.co
github.com/jorgeecardona
msg175373 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2012-11-11 17:23
Jorge, can we close this or do you still have a specific suggestion.
Also, if you reply by mail, please snip previous messages as they are already posted.
msg175375 - (view) Author: Jorge Cardona (Jorge.Cardona) Date: 2012-11-11 17:41
Hi, this can be closed. 

Thanks.
History
Date User Action Args
2022-04-11 14:57:38adminsetgithub: 60601
2020-03-12 07:07:49serhiy.storchakaunlinkissue39944 superseder
2020-03-12 06:42:57serhiy.storchakalinkissue39944 superseder
2019-12-09 00:53:18pschanelysetnosy: + pschanely
2012-11-11 18:21:38terry.reedysetresolution: works for me
stage: resolved
2012-11-11 17:41:26Jorge.Cardonasetstatus: open -> closed

messages: + msg175375
2012-11-11 17:23:01terry.reedysettype: behavior -> enhancement

messages: + msg175373
nosy: + terry.reedy
2012-11-03 18:47:43Jorge.Cardonasetmessages: + msg174668
2012-11-03 18:33:58loewissetmessages: + msg174662
2012-11-03 18:32:09loewissetnosy: + loewis

messages: + msg174661
versions: - Python 2.7, Python 3.2, Python 3.3
2012-11-03 18:31:05serhiy.storchakasetnosy: + rhettinger

components: + Library (Lib)
versions: + Python 3.3, Python 3.4
2012-11-03 18:13:13Jorge.Cardonacreate