[issue42454] Move slice creation to the compiler for constants

Christian Heimes report at bugs.python.org
Tue Nov 24 13:07:50 EST 2020


Christian Heimes <lists at cheimes.de> added the comment:

I'm slightly concerned about hashability of slice objects. Currently the slice constructor does not ensure that any slice parameter is a number. You can do horrible stuff like this:

>>> slice({})
slice(None, {}, None)

which of course fails later on:

>>> [][slice({})]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: slice indices must be integers or None or have an __index__ method

Would it be possible to move type checks to slice constructor?

----------
nosy: +christian.heimes

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


More information about the Python-bugs-list mailing list