[Python-Dev] Best Python API for exposing posix_spawn
Serhiy Storchaka
storchaka at gmail.com
Tue Jan 9 02:07:00 EST 2018
09.01.18 05:31, Nick Coghlan пише:
> On 8 January 2018 at 19:11, Pablo Galindo Salgado <pablogsal at gmail.com> wrote:
>> 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.
>
> Probably the closest prior art would be the os.DirEntry objects used
> for the items yielded from os.scandir - that is the same general idea
> (a dedicated Python class to represent a C struct), just in the other
> direction.
>
> As with DirEntry, I don't see any obvious value in making the new
> objects iterable though - we should be able to just use named field
> access in both the C and Python APIs.
Do you suggest to add a class corresponding to
posix_spawn_file_actions_t with methods corresponding to
posix_spawn_file_* functions?
class posix_spawn_file_actions:
def __init__(self): ...
def addclose(self, fildes): ...
def addopen(self, fildes, path, oflag, mode): ...
def adddup2(self, fildes, newfildes): ...
def destroy(self): pass
__del__ = destroy
This maximally corresponds the C API. But doesn't look Pythonic.
More information about the Python-Dev
mailing list