Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os.pipe() should return a structsequence (or namedtuple.) #68724

Open
JonathanSlenders mannequin opened this issue Jun 30, 2015 · 11 comments
Open

os.pipe() should return a structsequence (or namedtuple.) #68724

JonathanSlenders mannequin opened this issue Jun 30, 2015 · 11 comments
Labels
topic-IO type-feature A feature request or enhancement

Comments

@JonathanSlenders
Copy link
Mannequin

JonathanSlenders mannequin commented Jun 30, 2015

BPO 24536
Nosy @tiran, @Rosuav, @vadmium, @1st1, @jonathanslenders
Files
  • ospipe.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2015-06-30.07:19:17.144>
    labels = ['type-feature', 'expert-IO']
    title = 'os.pipe() should return a structsequence (or namedtuple.)'
    updated_at = <Date 2016-09-19.06:30:21.855>
    user = 'https://github.com/jonathanslenders'

    bugs.python.org fields:

    activity = <Date 2016-09-19.06:30:21.855>
    actor = 'christian.heimes'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['IO']
    creation = <Date 2015-06-30.07:19:17.144>
    creator = 'jonathan.slenders'
    dependencies = []
    files = ['39839']
    hgrepos = []
    issue_num = 24536
    keywords = ['patch']
    message_count = 11.0
    messages = ['245980', '245981', '245991', '245992', '246011', '246023', '246026', '246027', '246028', '246885', '276948']
    nosy_count = 5.0
    nosy_names = ['christian.heimes', 'Rosuav', 'martin.panter', 'yselivanov', 'jonathan.slenders']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue24536'
    versions = ['Python 3.6']

    @JonathanSlenders
    Copy link
    Mannequin Author

    JonathanSlenders mannequin commented Jun 30, 2015

    As discussed on python-ideas, os.pipe should return a structsequence instead of a plain tuple.

    To be decided is the naming for the read and write end.
    Personally, I'm in favour of using readfd/writefd.

    our_pipe = pipe()
    os.write(our_pipe.writefd, b'data')
    os.read(our_pipe.readfd, 1024)

    @JonathanSlenders JonathanSlenders mannequin added the topic-IO label Jun 30, 2015
    @Rosuav
    Copy link
    Contributor

    Rosuav commented Jun 30, 2015

    Another good option is read/write without the 'fd' suffix. Either works, I'd prefer the shorter one but by a small margin.

    @ethanfurman
    Copy link
    Member

    'read'/'write' is sufficient.

    +1 for the proposal.

    @JonathanSlenders
    Copy link
    Mannequin Author

    JonathanSlenders mannequin commented Jun 30, 2015

    Niki Spahiev made a valid argument saying that the following code is common:

    if not hasattr(src, 'read'): src = open(src)

    This will break if we name it 'read'/'write' like the methods of a file object.

    @1st1
    Copy link
    Member

    1st1 commented Jul 1, 2015

    +1 for readfd/writefd. I think 'fd' suffix is necessary to make it explicit that those aren't file objects.

    @1st1
    Copy link
    Member

    1st1 commented Jul 1, 2015

    Here's a patch, please review.

    @ethanfurman
    Copy link
    Member

    Nowhere else in the stdlib is 'readfd' defined, and 'writefd' is only used once in a test.

    I think tacking on the 'fd' is both too low level as well as misleading since these are not file descriptors.

    If there is no agreement on read/write (understandable since those are usually methods), then perhaps input/output?

    @ethanfurman
    Copy link
    Member

    Okay, scratch the "not file descriptors" part of my comment, but the rest still stands.

    @ethanfurman
    Copy link
    Member

    As for Niki's example:
    ---------------------

    --> src = os.pipe()
    --> src
    (3, 4)
    --> if not hasattr(src, 'read'): src = open(src)
    ... 
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: invalid file: (3, 4)

    This fails now. If they pass a pipe tuple into the new code they'll just get a different error somewhere else, which seems fine to me.

    @vadmium
    Copy link
    Member

    vadmium commented Jul 18, 2015

    The original Python-ideas thread: <https://www.marc.info/?t=143558954500004\>

    If you want shorter field names, how about just r and w (as they are currently documented)?

    os.write(our_pipe.w, b"data")
    os.read(our_pipe.r, 1024)

    “Input” and “output” would also work for me (though I am also happy with read, read_fd, etc). However it does seem a bit novel; in my experience people tend to say pipes have read and write ends, not inputs and outputs.

    os.write(our_pipe.input, b"data")
    os.read(our_pipe.output, 1024)

    @vadmium vadmium added the type-feature A feature request or enhancement label Jul 18, 2015
    @tiran
    Copy link
    Member

    tiran commented Sep 19, 2016

    In C programming common names for both ends are reader and writer. We could go with the pipes analogy and call the ends inlet and outlet.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    topic-IO type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    5 participants