[issue7951] Should str.format allow negative indexes when used for __getitem__ access?

Raymond Hettinger report at bugs.python.org
Mon Nov 29 17:01:36 EST 2021


Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:

I recommend not adding support for negative indexing to format() for accessing positional arguments.  There is almost no reason to do this because it almost always makes the format string less readable, because the number of arguments is always known in advance, and because the arguments are almost always used entirely rather than selectively.

Negative index support isn't a feature of the language.  Instead, it is a feature provided on a class by class basis, if it makes sense for that class and for its use cases.

We are not obliged to provide negative index support in places where it doesn't make sense or where it makes code less readable.  For example, the islice() function doesn't support negative indices because it doesn't make sense there.  Likewise, the Sequence ABC doesn't require negative index support or slice support.

----------

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


More information about the Python-bugs-list mailing list