[Python-3000] PEP 3138- String representation in Python 3000

Jim Jewett jimjjewett at gmail.com
Tue May 27 01:26:56 CEST 2008


Summary:

The only reason for this change is that __repr__ gets used when
__str__ *should* be used instead.

Fix that bug instead of making repr less predictable.

On 5/25/08, Stephen J. Turnbull <stephen at xemacs.org> wrote:
> Jim Jewett writes:

>   > I'm more worried that it might look like English, yet be subtly
>   > (and importantly) different.

> Let me remind you that I advocated that position, and (1) Martin
> shot me down hard, and (2) Guido indicated that it is a point,
> but he now seems happy enough not to worry about it.

I will agree that this is similar to the issue of non-ascii
identifiers.  If you can always trust everything on your system
completely, then it doesn't matter whether or not you can even read
the code.  If you might have to at least review things, then
confusability is an issue.

The question is where to draw the line.

I see print (and therefore str) as being intended for people, so they
should clearly use as much of unicode as available.

Identifiers are not usually part of the UI, so the case isn't as
strong (but i agree that it is now settled).

repr is not for normal UI; it is in explicit contrast to str.  I
therefore believe it should default to the safest possible
representation.

>... in view of the wide variety of cases where it seems to be
>  used for something other than diagnosing normally invisible
> features of output.

These are bugs.  I haven't yet seen a single case where it *should*
have been using repr instead of str.  Unfortunately, str itself
resorts to repr in some cases, and -- buggily -- then stays in repr
mode as it recurses down.

The right answer is not to make repr less predictable; it is to make
those str representations better -- if only by having them go back to
str(x) for the containers' contents.

>   > I just want it to be very easy to say "on my system, repr is ASCII".

> That is in all proposals.

Then I sometimes missed it.  And I'll note that it didn't happen for
identifiers.

>   > I would prefer that ASCII also be the default, so that people who want
>   > more characters opt in to receive them,

>... given the extent to
>  which repr is used to produce output meaningful to end-users
>  (vs. diagnostics for application and/or Python maintainers).

Again -- *why* is repr used instead of str?  As nearly as I can tell,
it is because of bugs (admittedly, often in builtin __str__
functions); making repr less predictable is a workaround rather than a
solution.

-jJ


More information about the Python-3000 mailing list