[ python-Bugs-1001011 ] str.join([ str-subtype-instance ]) misbehaves

SourceForge.net noreply at sourceforge.net
Mon Aug 2 16:25:49 CEST 2004


Bugs item #1001011, was opened at 2004-07-31 01:08
Message generated for change (Comment added) made by mwh
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1001011&group_id=5470

Category: Type/class unification
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Thomas Wouters (twouters)
Assigned to: Nobody/Anonymous (nobody)
Summary: str.join([ str-subtype-instance ]) misbehaves

Initial Comment:
Joining a list of string subtype instances usually
results in a single string instance:

  >>> class mystr(str): pass
  >>> type("".join([mystr("a"), mystr("b")]))
  <type 'str'>

But if the list only contains one object that is a
string subtype instance, that instance is returned
unchanged:

  >>> type("".join([mystr("a")]))
  <class '__main__.mystr'>

This can have odd effects, for instance when the result
of "".join(lst) is used as the returnvalue of a __str__
hook. "".join should perhaps return the type of the
joining string, but definately vary its type based on
the *number* of items its joining.



----------------------------------------------------------------------

>Comment By: Michael Hudson (mwh)
Date: 2004-08-02 15:25

Message:
Logged In: YES 
user_id=6656

What are you asking?  I agree it's a bug.  I'm sure you're 
competent to write a patch :-)

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1001011&group_id=5470


More information about the Python-bugs-list mailing list