New submission from Dávid Nemeskey <nemesk...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue42956>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to