This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Use namedtuple in string.Formatter.parse iterator response
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.7
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: cheryl.sabella, eric.smith, facundobatista, pablogsal, rhettinger, serhiy.storchaka
Priority: normal Keywords: patch

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:43adminsetgithub: 73882
2019-05-26 19:26:55rhettingersetstatus: open -> closed
resolution: rejected
stage: patch review -> resolved
2019-05-17 13:33:26cheryl.sabellasetnosy: + cheryl.sabella
messages: + msg342720
2017-10-18 09:30:37pablogsalsetmessages: + msg304571
2017-10-18 09:29:19pablogsalsetnosy: + pablogsal
messages: + msg304570
2017-10-18 00:44:28eric.smithsetmessages: + msg304548
2017-10-17 21:02:13serhiy.storchakasetmessages: + msg304533
2017-10-12 23:42:43pablogsalsetkeywords: + patch
stage: patch review
pull_requests: + pull_request3956
2017-03-03 17:58:53rhettingersetmessages: + msg288907
2017-03-03 08:46:34serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg288874
2017-03-03 08:32:39eric.smithsetversions: + Python 3.7, - Python 3.5
2017-03-03 08:28:52eric.smithsetmessages: + msg288873
2017-03-03 04:18:20rhettingersetnosy: + rhettinger
messages: + msg288854
2017-03-02 18:29:11eric.smithsetnosy: + eric.smith

title: Use namedtuple in Formatter.parse iterator response -> Use namedtuple in string.Formatter.parse iterator response
2017-03-02 15:34:03facundobatistacreate