[ python-Bugs-1751598 ] struni: str() doesn't call __str__() of subclasses of str
SourceForge.net
noreply at sourceforge.net
Wed Jul 11 03:48:05 CEST 2007
Bugs item #1751598, was opened at 2007-07-11 03:48
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1751598&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Interpreter Core
Group: Python 3000
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Christian Heimes (tiran)
Assigned to: Nobody/Anonymous (nobody)
Summary: struni: str() doesn't call __str__() of subclasses of str
Initial Comment:
In the py3k-struni branch the str() constructor doesn't use __str__ when the argument is an instance of a subclass of str. A user defined string can't change __str__().
It works in Python 2.5 and in the p3yk branch.
Python 3.0x (py3k-struni:56245, Jul 10 2007, 23:34:56)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class Mystr(str):
... def __str__(self): return 'v'
...
>>> s = Mystr('x')
>>> s
'x'
>>> str(s)
'x' # <- SHOULD RETURN 'v'
Python 2.5.1 (r251:54863, May 2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class Mystr(str):
... def __str__(self): return 'v'
...
>>> s = Mystr('x')
>>> s
'x'
>>> str(s)
'v'
Python 3.0x (p3yk:56180, Jul 6 2007, 23:35:08)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class Mystr(str):
... def __str__(self): return 'v'
...
>>> s = Mystr('x')
>>> s
'x'
>>> str(s)
'v'
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1751598&group_id=5470
More information about the Python-bugs-list
mailing list