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 rossbar
Recipients rossbar
Date 2020-11-13.18:47:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1605293276.23.0.88839506976.issue42352@roundup.psfhosted.org>
In-reply-to
Content
It would be nice if there were a way to get a string representation of a slice object in extended indexing syntax, e.g.

```
>>> myslice = slice(None, None, 2)
>>> print(myslice)
'::2'
```

One motivating use-case is in descriptive error messages, e.g.

```
TypeError(f"Can't slice {myobj}, try list({myobj})[{myslice}]")
```

In this case, it is much more natural for `myslice` to use the extended indexing syntax than the slice str/repr.

Perhaps this could be done via __str__, or if that is too big a change, maybe via __format__ e.g. `f"{myslice:asidx}"`

It's simple enough to write a conversion function, but this feels like a feature that would fit best upstream. I searched the issue tracker, PRs on GitHub, and the Python documentation and didn't see any related issues/PRs/articles.

xref: https://github.com/networkx/networkx/pull/4304
History
Date User Action Args
2020-11-13 18:47:56rossbarsetrecipients: + rossbar
2020-11-13 18:47:56rossbarsetmessageid: <1605293276.23.0.88839506976.issue42352@roundup.psfhosted.org>
2020-11-13 18:47:56rossbarlinkissue42352 messages
2020-11-13 18:47:56rossbarcreate