Skip to content

gh-116646: Remove _PyLong_FileDescriptor_Converter() #116736

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Include/internal/pycore_fileutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,6 @@ extern HRESULT PathCchSkipRoot(const wchar_t *pszPath, const wchar_t **ppszRootE
# define _Py_END_SUPPRESS_IPH
#endif /* _MSC_VER >= 1900 */

// Export for 'select' shared extension (Argument Clinic code)
PyAPI_FUNC(int) _PyLong_FileDescriptor_Converter(PyObject *, void *);

// Export for test_peg_generator
PyAPI_FUNC(char*) _Py_UniversalNewlineFgetsWithSize(char *, int, FILE*, PyObject *, size_t*);

Expand Down
33 changes: 33 additions & 0 deletions Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3698,6 +3698,39 @@ def test_my_double_sum(self):
with self.assertRaises(TypeError):
func(1., "2")

def test_get_file_descriptor(self):
# test 'file descriptor' converter: call PyObject_AsFileDescriptor()
get_fd = _testclinic_limited.get_file_descriptor

class MyInt(int):
pass

class MyFile:
def __init__(self, fd):
self._fd = fd
def fileno(self):
return self._fd

for fd in (0, 1, 2, 5, 123_456):
self.assertEqual(get_fd(fd), fd)

myint = MyInt(fd)
self.assertEqual(get_fd(myint), fd)

myfile = MyFile(fd)
self.assertEqual(get_fd(myfile), fd)

with self.assertRaises(OverflowError):
get_fd(2**256)
with self.assertWarnsRegex(RuntimeWarning,
"bool is used as a file descriptor"):
get_fd(True)
with self.assertRaises(TypeError):
get_fd(1.0)
with self.assertRaises(TypeError):
get_fd("abc")
with self.assertRaises(TypeError):
get_fd(None)


class PermutationTests(unittest.TestCase):
Expand Down
18 changes: 18 additions & 0 deletions Modules/_testclinic_limited.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,30 @@ my_double_sum_impl(PyObject *module, double x, double y)
}


/*[clinic input]
get_file_descriptor -> int

file as fd: fildes
/

Get a file descriptor.
[clinic start generated code]*/

static int
get_file_descriptor_impl(PyObject *module, int fd)
/*[clinic end generated code: output=80051ebad54db8a8 input=82e2a1418848cd5b]*/
{
return fd;
}


static PyMethodDef tester_methods[] = {
TEST_EMPTY_FUNCTION_METHODDEF
MY_INT_FUNC_METHODDEF
MY_INT_SUM_METHODDEF
MY_FLOAT_SUM_METHODDEF
MY_DOUBLE_SUM_METHODDEF
GET_FILE_DESCRIPTOR_METHODDEF
{NULL, NULL}
};

Expand Down
37 changes: 36 additions & 1 deletion Modules/clinic/_testclinic_limited.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 21 additions & 10 deletions Modules/clinic/fcntlmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading