➜

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, gvanrossum, ncoghlan
Date 2014-08-31.21:02:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1409518957.68.0.580016983518.issue22316@psf.upfronthosting.co.za>
In-reply-to
Content
Oooh, yes. The colon in a slice should be treated as a binary operator, with equal space before and after.

I think we can add this (as a new bullet following the bullet "Immediately before a comma, semicolon, or colon"):

- However, the colon in a slice acts like a binary operator, and
  should have equal amounts on either side.  In an extended slice,
  both colons must have the same amount of spacing applied. ::

      Yes: ham[1:9], ham[1:9:3], ham[:9:3], ham[1::3], ham[1:9:]
      Yes: ham[lower + offset : upper + offset], ham[lower : upper : 3]
      No: ham[1: 9], ham[1 :9]


I'm not sure what to recommend for extended slices when one or several of the slots are empty; my intuition suggests that there should be no spaces around any colons in that case, but I'm not sure what to do if you really have a long expression as one slot. Which is better?

    ham[lower + 1 :: step]

or

    ham[lower + 1 : : step]

similar for other cases, e.g.

    ham[lower + 1 : upper + 1 :]

vs.

    ham[lower + 1 : upper + 1 : ]

To me, *all* of those feel weird.
History
Date User Action Args
2014-08-31 21:02:37gvanrossumsetrecipients: + gvanrossum, barry, ncoghlan, docs@python, Guido.van.Rossum, anthonymayer
2014-08-31 21:02:37gvanrossumsetmessageid: <1409518957.68.0.580016983518.issue22316@psf.upfronthosting.co.za>
2014-08-31 21:02:37gvanrossumlinkissue22316 messages
2014-08-31 21:02:37gvanrossumcreate