classification
Title: Should posix functions that accept fd also accept objects with .fileno()?
Type: enhancement Stage: needs patch
Components: Versions: Python 3.5
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, larry, vstinner
Priority: low Keywords:

Created on 2014-01-29 03:48 by larry, last changed 2019-06-20 16:41 by nanjekyejoannah.

Messages (2)
msg209613 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2014-01-29 03:48
While working on posixmodule.c today I noticed that some functions that accept file descriptors call PyObject_AsFileDescriptor().  This function accepts ints.  It *also* accepts objects that expose a .fileno() attribute, calling that attribute and using the integer it returns.

There are *other* functions in posixmodule.c that accept file descriptors that call _fd_converter(), which just looks for an int with a proper value.

I figure it should be one way or the other.  Should everything in posix that accepts file descriptor ints accept the .fileno() convention too?
msg209614 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2014-01-29 03:55
The functions that use PyObject_AsFileDescriptor() also call _PyVerify_fd(), which magically determines whether or not the file descriptor is valid.  Only works on Windows though.
History
Date User Action Args
2019-06-20 16:41:32nanjekyejoannahsetnosy: + vstinner
2014-01-29 07:17:23Arfreversetnosy: + Arfrever
2014-01-29 03:55:23larrysetmessages: + msg209614
2014-01-29 03:48:20larrycreate