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: termios.tcgetattr should return namedtuple
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, iritkatriel, pitrou, r.david.murray, techtonik
Priority: normal Keywords:

Created on 2013-07-23 12:06 by techtonik, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
DictRecord.py techtonik, 2013-07-24 06:37
Messages (10)
msg193595 - (view) Author: anatoly techtonik (techtonik) Date: 2013-07-23 12:05
Names of field for tuple returned by tcgetattr are already in documentation at http://docs.python.org/2/library/termios.html

It would be nice to get them into code.
msg193596 - (view) Author: anatoly techtonik (techtonik) Date: 2013-07-23 12:22
Actually namedtuple doesn't suit the use case well. The use case is to read termios config, (re)set flags set it back. The attributes should be mutable.
msg193598 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2013-07-23 12:44
namedtuple has a _replace method, but I agree that it would be an incompatible change. "namedlist" someone?

class tcattributes(object):
    __slots__ = ['iflag', 'oflag', 'cflag', 'lflag', 'ispeed', 'ospeed', 'cc']

    def __new__(cls, values):
        self = object.__new__(cls)
        for attr, value in zip(cls.__slots__, values):
            setattr(self, attr, value)
        return self

    def __getitem__(self, index):
        return getattr(self, self.__slots__[index])
msg193601 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-07-23 13:48
Returning a list was probably silly to begin with (a dict would have been more natural).
However, I don't think I want to see such a thing as a namedlist in the stdlib. :-(
msg193627 - (view) Author: anatoly techtonik (techtonik) Date: 2013-07-24 06:37
I've made my own monster, attached.
msg193628 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2013-07-24 08:28
You need a better use case though.
termios awful constant names ('TIOCGWINSZ') and values ('\x1b') won't become more easy with a nametuple.
msg193638 - (view) Author: anatoly techtonik (techtonik) Date: 2013-07-24 12:05
Do not hijack the issue - value interpretation is the next step, which better keep out of scope for this improvement. termios is a C interface, which documents the meaning of TIOCGWINSZ and has defined names for structure entries, such as lflag. This issue is to make Python code at least as readable as C.

C doesn't allow you to revert value meaning from ('\x1b') to text form.
msg193639 - (view) Author: anatoly techtonik (techtonik) Date: 2013-07-24 12:06
If you need a better use case for DictRecord, urlparse is another one.
msg193652 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-07-24 14:47
Anatoly: FYI "Do not hijack the issue" is not a collaborative conversation style in English.  A more collaborative conversation style would be to leave out that part of the sentence, and just say that you think value interpretation should be a separate, later issue (with your reasons, of course).
msg415995 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-03-25 11:39
The patch has no tests, the use case is not clear and it's been 9 years. Closing.
History
Date User Action Args
2022-04-11 14:57:48adminsetgithub: 62735
2022-03-25 11:39:01iritkatrielsetstatus: open -> closed

nosy: + iritkatriel
messages: + msg415995

stage: resolved
2013-07-24 14:47:47r.david.murraysetnosy: + r.david.murray
messages: + msg193652
2013-07-24 12:06:54techtoniksetmessages: + msg193639
2013-07-24 12:05:02techtoniksetstatus: closed -> open

messages: + msg193638
2013-07-24 08:28:45amaury.forgeotdarcsetstatus: open -> closed
resolution: works for me
messages: + msg193628
2013-07-24 06:37:35techtoniksetfiles: + DictRecord.py

messages: + msg193627
2013-07-23 13:48:16pitrousetnosy: + pitrou
messages: + msg193601
2013-07-23 12:44:09amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg193598
2013-07-23 12:22:08techtoniksetmessages: + msg193596
2013-07-23 12:06:00techtonikcreate