[Python-ideas] Disallow "00000" as a synonym for "0"

Nick Coghlan ncoghlan at gmail.com
Mon Jul 20 02:38:02 CEST 2015

On 20 Jul 2015 2:38 am, "Chris Angelico" <rosuav at gmail.com> wrote:
> On Mon, Jul 20, 2015 at 2:22 AM, Ron Adam <ron3200 at gmail.com> wrote:

> > A social reason for this limitation is that a number of other languages
> > use a leading digit 0 to define octal numbers.  And this helps catch
> > errors due to copying numbers directly in that case.  (Python uses "0o"
> > not just "0".)
> Python 2 also supported C-style "0777" to mean 511, and it's all
> through Unix software (eg "0777" is a common notation for a
> world-writable directory's permission bits; since there are three bits
> (r/w/x) for each of the three categories (u/g/o), it makes sense to
> use octal). Supporting "0777" in source code and having it mean 777
> decimal would be extremely confusing, which is why it's a straight-up
> error in Python 3.

Exactly - the special case here is *dis*allowing leading zeroes for
non-zero integer literals, since we can't know if they're supposed to be
octal values or not, or if the "b" or "x" was left out of a binary or hex
literal that has been padded out to a fixed number of bits, or if the
decimal point was left out of a floating point literal.

The one integer literal case that *could* be reliably kept consistent with
the general mathematical notation of "leading zeroes are permitted, but
have no significance" was zero itself, which is what was done.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150720/cb8a9b69/attachment.html>

More information about the Python-ideas mailing list