[issue39985] str.format and string.Formatter subscript behaviors diverge

2020-03-19 Thread Eric V. Smith


Eric V. Smith  added the comment:

In fact, this is a duplicate of issue27307, so I'm going to close this.

--
resolution:  -> duplicate
stage: patch review -> resolved
status: open -> closed
superseder:  -> string.Formatter does not support key/attribute access on 
unnumbered fields

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39985] str.format and string.Formatter subscript behaviors diverge

2020-03-19 Thread Eric V. Smith


Eric V. Smith  added the comment:

Can you see if the patch in issue27307 solves your problem?

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39985] str.format and string.Formatter subscript behaviors diverge

2020-03-18 Thread Maxwell Bernstein


Change by Maxwell Bernstein :


--
keywords: +patch
pull_requests: +18418
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/19065

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39985] str.format and string.Formatter subscript behaviors diverge

2020-03-16 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +eric.smith

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39985] str.format and string.Formatter subscript behaviors diverge

2020-03-16 Thread Maxwell Bernstein


New submission from Maxwell Bernstein :

As I understand it, str.format and string.Formatter are supposed to behave the
same, with string.Formatter being a pluggable variant. While poking at
string.Formatter, I noticed that they do not behave the same when formatting a
nameless subscript:

```
import string
str.format("{[0]}", "hello")  # => "h"
string.Formatter().format("{[0]}", "hello")  # => KeyError("")
```

They seem to work the same in the case where the arg is either indexed by
number or by name:

```
import string
str.format("{0[0]}", "hello")  # => "h"
string.Formatter().format("{0[0]}", "hello")  # => "h"
str.format("{a[0]}", a="hello")  # => "h"
string.Formatter().format("{a[0]}", a="hello")  # => "h"
```

After some digging, I have come up with a couple ideas:

* Change _string.formatter_field_name_split to treat an empty string field name
  as 0, so that string.Formatter.get_value looks up the arg in args, instead of
  kwargs
* Change string.Formatter.get_value to treat empty string key as 0, and look up
  the arg in args, instead of kwargs

I'm happy to submit a PR if people find one of these two solutions palatable or
have some solutions of their own.

(Note: this may appear in other versions, but I don't have them on my machine
to test.)

--
components: Library (Lib)
messages: 364382
nosy: tekknolagi
priority: normal
severity: normal
status: open
title: str.format and string.Formatter subscript behaviors diverge
type: behavior
versions: Python 2.7, Python 3.6, Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com