classification
Title: strings don't seem to roundtrip with repr()
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.0, Python 2.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, mark
Priority: normal Keywords:

Created on 2008-06-25 13:33 by mark, last changed 2008-06-25 13:51 by amaury.forgeotdarc. This issue is now closed.

Messages (2)
msg68728 - (view) Author: Mark Summerfield (mark) * Date: 2008-06-25 13:33
With 2.5.2 and 30b1 strings don't round trip like numbers do.

I guess it has been like this a long time so isn't a bug, but it does
seem inconsistent.

Both 2.5.2 and 30b1:

>>> x = 5
>>> x == int(repr(x))
True
>>> x = "Test Text"
>>> x == str(repr(x))
False

The reason is that an extra set of enclosing quotes are added.
msg68729 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-06-25 13:51
repr() is supposed to round-trip with eval() for common types.

str() is the function that round-trips with the original type:

>>> x = 5
>>> x == int(str(x))
True
>>> x = "Test Text"
>>> x == str(str(x))    #  :-)
True
History
Date User Action Args
2008-06-25 13:51:06amaury.forgeotdarcsetstatus: open -> closed
resolution: not a bug
messages: + msg68729
nosy: + amaury.forgeotdarc
2008-06-25 13:33:50markcreate