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.

Author gvanrossum
Recipients Guido.van.Rossum, anthonymayer, barry, docs@python, ezio.melotti, gvanrossum, ncoghlan
Date 2014-09-01.02:02:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1409536962.32.0.625904829913.issue22316@psf.upfronthosting.co.za>
In-reply-to
Content
Just like for other binary operators (except for the ones mentioned as always needing spaces), the spaces around ":" are neither mandatory nor objectionable.  I am not making up a new rule, this is how I've always thought -- we just have to make it explicit that x[1: n] is wrong.

How about this:

- However, in a slice the colon acts like a binary operator, and
  should have equal amounts on either side (treating it as the
  operator with the lowest priority).  In an extended slice, both
  colons must have the same amount of spacing applied.  Exception:
  when a slice parameter is omitted, the space is omitted. ::

  Yes::

      ham[1:9], ham[1:9:3], ham[:9:3], ham[1::3], ham[1:9:]
      ham[lower:upper], ham[lower:upper:], ham[lower::step]
      ham[lower+offset : upper+offset]
      ham[: upper_fn(x) : step_fn(x)], ham[:: step_fn(x)]
      ham[lower + offset : upper + offset]

  No::

      ham[lower + offset:upper + offset]
      ham[1: 9], ham[1 :9], ham[1:9 :3]
      ham[lower : : upper]
      ham[ : upper]
History
Date User Action Args
2014-09-01 02:02:42gvanrossumsetrecipients: + gvanrossum, barry, ncoghlan, ezio.melotti, docs@python, Guido.van.Rossum, anthonymayer
2014-09-01 02:02:42gvanrossumsetmessageid: <1409536962.32.0.625904829913.issue22316@psf.upfronthosting.co.za>
2014-09-01 02:02:42gvanrossumlinkissue22316 messages
2014-09-01 02:02:41gvanrossumcreate