09.01.18 01:05, Gregory P. Smith пише:
On Mon, Jan 8, 2018 at 12:36 PM Serhiy Storchaka <storch...@gmail.com <mailto:storch...@gmail.com>> wrote:

    08.01.18 11:11, Pablo Galindo Salgado пише:
     > Following Gregory's comment on the PR I understand that he is
    proposing
     > to have three objects in the os module representing each action
    and pass
     > a sequence of these objects to the Python API. What I am not sure
    about
     > this is that there is no previous example of such classes in the os
     > module for other similar APIs and therefore I am not sure if
    there is a
     > better approach.

    I would pass a sequence like:

    [(os.close, 0),
       (os.open, 1, '/tmp/mylog', os.O_WRONLY, 0o700),
       (os.dup2, 1, 2),
    ]


i agree with just a list of tuples, but i suggest creating namedtuple instances in the posix module for the purpose (one each for close, dup2, open) .  Don't put a reference to a function in the tuple as Serhiy suggested as, while obvious what it means, it gives the wrong impression to the user: nothing is calling the Python functions.  This is a posix API that takes a list of arguments for a specific set of system calls for _it_ to make for us in a specific order.

Creating three new classes has higher cost than creating three singletones. There are some advantages of using existing functions as tags.

But this is not the only possible interface. If there is a single order of actions (first close, then open, finally dup2), actions can be specified as three keyword-only arguments taking sequences of integers or tuples:

posix_spawn(..., close=[0],
            open=[(1, '/tmp/mylog', os.O_WRONLY, 0o700)],
            dup2=[(1, 2)])

But this perhaps is not able to express all useful cases.

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to