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: ref/ref3.tex: Remove claim about eval(repr(obj))
Type: Stage:
Components: Documentation Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: gvanrossum Nosy List: akuchling, gvanrossum, tim.peters
Priority: normal Keywords:

Created on 2000-12-19 03:16 by akuchling, last changed 2022-04-10 16:03 by admin. This issue is now closed.

Messages (6)
msg2708 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2000-12-19 03:16
The description of __repr__ in section 3 of the Language Ref
says " This should normally look like a
valid Python expression that can be used to recreate an object with
the same value."  This isn't true, isn't a good idea, 
and often isn't possible anyway.  Rewrite this to emphasize 
that repr() is usually for debugging.

msg2709 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2000-12-19 03:19
Assigning to GvR, since I assume the LangRef is his responsibility.
I can rewrite the text if the change's intent is approved.
msg2710 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2000-12-19 03:29
Harrumph.  For starters it's true for strings, ints, longs and (as of 1.6) floats, plus lists, tuples and dicts recursively composed of these.  And it's a great idea.  I believe Guido meant what he wrote here:  "should" -- no bug.
msg2711 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2000-12-19 04:08
I disagree with the "isn't a good idea" part.

While it's indeed not a good idea to use eval(repr(x)), it *is* a good idea to make repr(x) look like a syntactically correct expression that would recreate an object with the same value as x, given the appropriate environment (e.g. imported the class or factory function).

I hate non-standard object types whose repr() is indistinguishable from that of a similar standard object -- e.g. UserList makes this mistake, and xrange() used to pretend it was a tuple.

Nevertheless I'll try to think of something to add to the docs.
msg2712 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2000-12-19 04:18
Checked something in as rev. 1.55.  Let me know what you think.
msg2713 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2000-12-19 14:11
That's a bit better, so I won't re-open the bug on you.  (Noticed a small typo and fixed it.)
History
Date User Action Args
2022-04-10 16:03:34adminsetgithub: 33611
2000-12-19 03:16:05akuchlingcreate