[New-bugs-announce] [issue42956] Easy conversion between range and slice

Dávid Nemeskey report at bugs.python.org
Mon Jan 18 05:31:17 EST 2021


New submission from Dávid Nemeskey <nemeskeyd at gmail.com>:

It would be nice if there was an easy way to convert a range to a slice and vice versa. At least superficially the two are almost the same(*), yet if one wants to convert a slice to a range, he has to go through hoops to avoid potential errors, ending up with code such as:

s = slice(1, 10, 2)
r = range(s.start or 0, s.stop, s.step or 1)

It would be much nicer if the range and slice functions had a signature that accepts the other, which would simplify the above to just r(s).

(*) I don't know the implementation details, but is it even important to have to different objects for effectively the same concept? Cannot these two just be merged?

----------
messages: 385184
nosy: nemeskeyd
priority: normal
severity: normal
status: open
title: Easy conversion between range and slice
type: enhancement
versions: Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42956>
_______________________________________


More information about the New-bugs-announce mailing list