Issue 29696: Use namedtuple in string.Formatter.parse iterator response (original) (raw)

Created on 2017-03-02 15:34 by facundobatista, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 3980 closed pablogsal,2017-10-12 23:42
Messages (10)
msg288807 - (view) Author: Facundo Batista (facundobatista) * (Python committer) Date: 2017-03-02 15:34
Right now: >>> Formatter().parse("mira como bebebn los peces en el {rio} {de} {la} plata") <formatteriterator object at 0x7f1fc7c7f150> >>> next(_) ('mira como bebebn los peces en el ', 'rio', '', None) This returned tuple should be a namedtuple, so it's self-explained for people exploring this (and usage of the fields become clearer)
msg288854 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2017-03-03 04:18
I think this is all C coded, so it would entail making a new structseq object.
msg288873 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2017-03-03 08:28
It's in string.py, so it would be easy just to add a namedtuple there: class Formatter: ... def parse(self, format_string): return _string.formatter_parser(format_string) I don't see a need to add a structseq to _string, since it's a private API.
msg288874 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-03-03 08:46
collections is a moderately heavy module with many dependencies. string is a light module, it imports only _string. I'm -1 for using namedtuple in the string module.
msg288907 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2017-03-03 17:58
I would also rather see string.py left light weight. It would be better to change the upstream C code to use structseq.
msg304533 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-10-17 21:02
I'm not convinced that a named tuple is needed here.
msg304548 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2017-10-18 00:44
It does seem like overkill for something that's rarely used. I'm -0 on the structseq version.
msg304570 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2017-10-18 09:29
IMHO this change makes things a bit more consistent. In lots of places when a tuple is returned, a `structseq` is used to improve readability on the returned result. Some examples of this are: * grp.struct_group * os.terminal_size * pwd.struct_passwd * resource.struct_rusage * signal.struct_siginfo * time.struct_time * spwd.struct_spwd * sys.float_info * sys.int_info * string.FormatterItem * sys.hash_info * sys.getwindowsversion * sys.flags * sys.version_info * sys.thread_info
msg304571 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2017-10-18 09:30
With the exception of string.FormatterItem, which is the change at hand.
msg342720 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2019-05-17 13:33
It looks like Pablo's patch for this was good, but then closed because the idea was rejected. Should this ticket also be closed as rejected?
History
Date User Action Args
2022-04-11 14:58:43 admin set github: 73882
2019-05-26 19:26:55 rhettinger set status: open -> closedresolution: rejectedstage: patch review -> resolved
2019-05-17 13:33:26 cheryl.sabella set nosy: + cheryl.sabellamessages: +
2017-10-18 09:30:37 pablogsal set messages: +
2017-10-18 09:29:19 pablogsal set nosy: + pablogsalmessages: +
2017-10-18 00:44:28 eric.smith set messages: +
2017-10-17 21:02:13 serhiy.storchaka set messages: +
2017-10-12 23:42:43 pablogsal set keywords: + patchstage: patch reviewpull_requests: + <pull%5Frequest3956>
2017-03-03 17:58:53 rhettinger set messages: +
2017-03-03 08:46:34 serhiy.storchaka set nosy: + serhiy.storchakamessages: +
2017-03-03 08:32:39 eric.smith set versions: + Python 3.7, - Python 3.5
2017-03-03 08:28:52 eric.smith set messages: +
2017-03-03 04🔞20 rhettinger set nosy: + rhettingermessages: +
2017-03-02 18:29:11 eric.smith set nosy: + eric.smithtitle: Use namedtuple in Formatter.parse iterator response -> Use namedtuple in string.Formatter.parse iterator response
2017-03-02 15:34:03 facundobatista create