[Python-ideas] Disallow "00000" as a synonym for "0"
Steven D'Aprano
steve at pearwood.info
Sun Jul 19 13:03:22 CEST 2015
On Sat, Jul 18, 2015 at 01:35:49PM -0400, random832 at fastmail.us wrote:
> On Fri, Jul 17, 2015, at 10:28, Eric V. Smith wrote:
> > On 07/16/2015 06:15 AM, Neil Girdhar wrote:
> > > As per this
> > > question: http://stackoverflow.com/questions/31447694/why-does-python-3-allow-00-as-a-literal-for-0-but-not-allow-01-as-a-literal
> > >
> > > It seems like Python accepts "000000000" to mean "0". Whatever the
> > > historical reason, should this be deprecated?
> >
> > No. It would needlessly break working code.
>
> Counter-proposal - allow 00001 through 00009 since they are equally
> unambiguous.
Do you mean up to 007, since they are the same in oct and dec?
In either case, that introduces even more special cases. Whether it is
one special case, 000, or eight, or ten, 000 through 009, the questions
remain:
- why does (let's say) `n = 02` work, but `n = 012` fail?
- why would you intentionally write `n = 00' when you could simply
write `n = 0`?
Backwards compatibilty aside, I don't think there's any reason to keep
this feature. I suspect that it can only mask typos, not be used for any
sensible reason. Back when 000 meant octal zero, it might have made
sense to write it that way to align with a bunch of other octal numbers,
but now you would surely write 0o00 to align with 0o10.
http://bugs.python.org/issue24668
--
Steve
More information about the Python-ideas
mailing list