New submission from Ross Barnowski <ross...@berkeley.edu>:
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 ---------- messages: 380921 nosy: rossbar priority: normal severity: normal status: open title: A string representation of slice objects with colon syntax type: enhancement versions: Python 3.10 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue42352> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com