[Python-ideas] Deprecating repr() and the like
Antoine Pitrou
solipsis at pitrou.net
Fri Aug 9 22:56:56 CEST 2013
On Fri, 9 Aug 2013 15:52:00 -0500
Tim Peters <tim.peters at gmail.com> wrote:
> [Serhiy Storchaka]
> >> repr(), ascii() and one-argument str() can be deprecated and removed in
> >> Python 5.0 because they are redundant and can be expressed as a simple
> >> formatting:
> >>
> >> repr(x) == '%r'%(x,) == '{!r}'.format(x)
> >> ascii(x) == '%a'%(x,) == '{!a}'.format(x)
> >> str(x) == '%s'%(x,) == '{}'.format(x)
> >>
> >> We also can deprecate string concatenation for the same reason:
> >>
> >> s1 + s2 == '%s%s'%(s1,s1) == '{}{}'.format(s1,s2) == ''.join([s1,s2])
>
> And don't forget the digit 1! It looks too much like lowercase letter
> L. It would be silly require constructs like 42 // 42 instead, so
> let's add a new builtin "one":
>
> >>> 1
> SyntaxError: invalid syntax
> >>> one == 42 // 42
> True
> >>> one
> 1
>
> I'm not sure how to replace the confusing output from that last line ;-)
Just fix one's repr() (which doesn't exist anymore).
Regards
Antoine.
More information about the Python-ideas
mailing list