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

2021-11-30 Thread Eric V. Smith
Eric V. Smith added the comment: I'm closing this as "won't fix" for the negative indexing functionality. If someone wants to open an new documentation issue (and ideally provide a PR), that would be welcome. -- resolution: -> wont fix stage: needs patch -> resolved status: open ->

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

2021-11-29 Thread Raymond Hettinger
Raymond Hettinger 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

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

2021-11-29 Thread Irit Katriel
Irit Katriel added the comment: Reproduced on 3.11, and the error message is a little weirder now: >>> "{0[-1]}".format('fox') Traceback (most recent call last): File "", line 1, in TypeError: string indices must be integers, not 'str' -- nosy: +iritkatriel versions: +Python 3.11

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

2019-07-13 Thread Ilya Kamenshchikov
Ilya Kamenshchikov added the comment: Py3.6+ f-strings support any indexing as they actually evaluate python expressions. >>> a = ['Java', 'Python'] >>> var = f"Hello {a[-1]}" Hello Python -- nosy: +Ilya Kamenshchikov ___ Python tracker

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

2019-04-26 Thread Eric V. Smith
Eric V. Smith added the comment: I'm not sure where (or if) it's defined in the Python docs, but in PEP 3101 it's in https://www.python.org/dev/peps/pep-3101/#simple-and-compound-field-names: "It should be noted that the use of 'getitem' within a format string is much more limited than its

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

2019-04-25 Thread Éric Araujo
Éric Araujo added the comment: A side question: where is it defined that in `{thing[0]}`, 0 will be parsed as an integer? The PEP shows `{thing[name]}` and mentions that this is not Python but a smaller mini-language, with `name` always a string, no quotes needed or permitted. --

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

2016-05-28 Thread Mark Lawrence
Changes by Mark Lawrence : -- nosy: -BreamoreBoy ___ Python tracker ___ ___

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

2016-05-27 Thread Marco Buttu
Marco Buttu added the comment: The error message is misleading: >>> s = '{names[-1]} loves {0[1]}' >>> s.format(('C', 'Python'), names=('Dennis', 'Guido')) Traceback (most recent call last): ... TypeError: tuple indices must be integers or slices, not str -- nosy: +marco.buttu

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

2014-08-18 Thread Mark Lawrence
Mark Lawrence added the comment: msg216038 suggests three options for the doc patch, does anybody have any preference or a better alternative? -- nosy: +BreamoreBoy ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7951

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

2014-04-13 Thread Terry J. Reedy
Changes by Terry J. Reedy tjre...@udel.edu: -- assignee: docs@python - terry.reedy ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7951 ___ ___

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

2014-04-13 Thread Terry J. Reedy
Terry J. Reedy added the comment: The doc bug is that the grammar block uses 'integer' (linked to https://docs.python.org/3/reference/lexical_analysis.html#grammar-token-integer) in arg_name ::= [identifier | integer] element_index ::= integer | index_string when it should

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

2014-04-12 Thread Eric V. Smith
Changes by Eric V. Smith e...@trueblade.com: -- assignee: eric.smith - docs@python nosy: +docs@python ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7951 ___

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

2014-04-11 Thread Terry J. Reedy
Terry J. Reedy added the comment: Either leading sign, '+' or '-', cause string interpretation, so I think 'unsigned integer' should be the term in the doc. '{0[-1]}'.format({'-1': 'neg int key'}) 'neg int key' '{0[+1]}'.format({'+1': 'neg int key'}) 'neg int key' '{0[+1]}'.format([1,2,3])

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

2014-02-03 Thread Mark Lawrence
Changes by Mark Lawrence breamore...@yahoo.co.uk: -- nosy: -BreamoreBoy ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7951 ___ ___

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

2013-05-26 Thread Mark Lawrence
Mark Lawrence added the comment: Todd's patch strikes me as fine. If something more detailed is needed I think it would be better to raise a separate issue. -- nosy: +BreamoreBoy ___ Python tracker rep...@bugs.python.org

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

2013-04-19 Thread Todd Rovito
Changes by Todd Rovito rovit...@gmail.com: -- nosy: +Todd.Rovito ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7951 ___ ___ Python-bugs-list

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

2013-04-19 Thread Todd Rovito
Todd Rovito added the comment: Here is a simple patch that simply explains negative indexes and negative slices are not supported for the string format documentation. Perhaps more documentation needs to be created else where to help explain why all collections do not need to support negative

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

2010-09-12 Thread Éric Araujo
Éric Araujo mer...@netwok.org added the comment: Thank you for the detailed argument, Raymond. I’m +1 on turning this into a doc bug. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7951

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

2010-09-12 Thread Raymond Hettinger
Changes by Raymond Hettinger rhettin...@users.sourceforge.net: -- components: +Documentation -Interpreter Core ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7951 ___

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

2010-09-09 Thread Florent Xicluna
Changes by Florent Xicluna florent.xicl...@gmail.com: -- nosy: +flox ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7951 ___ ___ Python-bugs-list

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

2010-09-09 Thread Raymond Hettinger
Raymond Hettinger rhettin...@users.sourceforge.net added the comment: After more thought, I'm -1 on this. Consistency is a weak argument in favor of this. We need to be more use case drivenm and it there is no evidence that this is needed. Also, there is a reasonable concern that using

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

2010-08-11 Thread Raymond Hettinger
Raymond Hettinger rhettin...@users.sourceforge.net added the comment: Fixing-up str formatting idiosyncracies does not fall under the moratorium and is helpful in getting 3.x to be usable. That being said, I'm not convinced that this is actually a helpful feature. Not all objects supporting

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

2010-08-11 Thread Matthew Barnett
Matthew Barnett pyt...@mrabarnett.plus.com added the comment: I agree with Kamil and Germán. I would've expected negative indexes for sequences to work. Negative indexes for fields is a different matter. -- ___ Python tracker rep...@bugs.python.org

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

2010-08-09 Thread Terry J. Reedy
Terry J. Reedy tjre...@udel.edu added the comment: I believe this is covered by the PEP3003 3.2 change moratorium. -- nosy: +terry.reedy versions: +Python 3.3 -Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7951

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

2010-06-25 Thread Germán L . Osella Massa
Germán L. Osella Massa gose...@gmail.com added the comment: Well, using negative indexes for fields can be thought as a new feature with all the consequences mentioned before BUT negative indexes for accessing elements from a sequence, IMHO, is something that anyone would expected to work.

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

2010-06-23 Thread Kamil Kisiel
Kamil Kisiel kisi...@users.sourceforge.net added the comment: While I agree this functionality isn't strictly necessary I think it makes sense from a semantic point of view. I ran in to this issue today while writing some code and I simply expected the negative syntax to work, given that the

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

2010-06-18 Thread Germán L . Osella Massa
Germán L. Osella Massa gose...@gmail.com added the comment: I finally managed to get the time to finish the patch that allows negative indexes inside square brackets so now they work with the same semantics as in a python expression: '{0[-1]}'.format(['abc', 'def']) 'def'

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

2010-06-18 Thread Germán L . Osella Massa
Changes by Germán L. Osella Massa gose...@gmail.com: Added file: http://bugs.python.org/file17713/format_negative_indexes-3.2.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7951 ___

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

2010-06-18 Thread Germán L . Osella Massa
Germán L. Osella Massa gose...@gmail.com added the comment: I forgot to mention that I also made a patch against py3k (was the same code). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7951

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

2010-06-18 Thread Raymond Hettinger
Raymond Hettinger rhettin...@users.sourceforge.net added the comment: Perhaps this ought to be discussed on python-ideas or python-dev for a bit. It is not entirely clear that this is a GoodThingToDo(tm) nor is it clear that we want other Python implementations to have to invest the same

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

2010-06-18 Thread Eric Smith
Eric Smith e...@trueblade.com added the comment: I agree with Raymond. I'm not convinced it allows you to write any code that you can't currently write, and I'm fairly sure it violates the moratorium. Implementing this would clearly put a burden on other implementations. Marking as after

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

2010-06-14 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com added the comment: I (reluctantly) agree it's surprising that {0[-1]}.format(args) fails. And I suppose that if it were allowed then it would also make sense to consider {-1}.format(*args) as well, in order to preserve the equivalence between

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

2010-06-14 Thread Eric Smith
Eric Smith e...@trueblade.com added the comment: Addressing just the last part of Mark's message right now: The PEP goes on to say: Implementation note: The implementation of this proposal is not required to enforce the rule about a simple or dotted name being a valid Python

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

2010-06-14 Thread Matthew Barnett
Matthew Barnett pyt...@mrabarnett.plus.com added the comment: Re: msg107776. If it looks like an integer (ie, can be converted to an integer by 'int') then it's positional, otherwise it's a key. An optimisation is to perform a quick check upfront to see whether it starts like an integer.

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

2010-06-14 Thread Mark Dickinson
Mark Dickinson dicki...@gmail.com added the comment: Matthew: would that include allowing whitespace, then? int('\t\n+56') 56 -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7951 ___

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

2010-06-14 Thread Matthew Barnett
Matthew Barnett pyt...@mrabarnett.plus.com added the comment: That's a good question. :-) Possibly just an optional sign followed by one or more digits. Another possibility that occurs to me is for it to default to positional if it looks like an integer, but allow quoting to force it to be a

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

2010-06-14 Thread Eric Smith
Eric Smith e...@trueblade.com added the comment: I can see the point of allowing negative indices for a consistency point, but is there really any practical problem that's currently causing people hardship that this would solve? As for the rest of it, I think it's just not worth the

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

2010-06-14 Thread Matthew Barnett
Matthew Barnett pyt...@mrabarnett.plus.com added the comment: Your original: {0[-1]}.format('fox') is a worse gotcha than: {-1}.format('fox') because you're much less likely to want to do the latter. It's one of those things that it would be nice to have fixed, or we could just add

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

2010-06-13 Thread Eric Smith
Changes by Eric Smith e...@trueblade.com: -- versions: -Python 2.7 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7951 ___ ___ Python-bugs-list

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

2010-06-13 Thread Eric Smith
Eric Smith e...@trueblade.com added the comment: Closed issue 8985 as a duplicate of this; merging nosy lists. -- nosy: +gosella, mark.dickinson, merwok ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7951

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

2010-06-13 Thread Eric Smith
Changes by Eric Smith e...@trueblade.com: -- stage: - needs patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7951 ___ ___ Python-bugs-list

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

2010-02-18 Thread Matthew Barnett
Matthew Barnett pyt...@mrabarnett.plus.com added the comment: On a related note, this doesn't work either: {-1}.format(x, y, z) Traceback (most recent call last): File pyshell#3, line 1, in module {-1}.format(x, y, z) KeyError: '-1' It could return z. It also rejects a leading '+', but

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

2010-02-17 Thread Eric Smith
New submission from Eric Smith e...@trueblade.com: It surprised me that this doesn't work: {0[-1]}.format('fox') Traceback (most recent call last): File stdin, line 1, in module TypeError: string indices must be integers I was expecting it to be equivalent to: {0[2]}.format('fox') 'x' I