Skip to content

Commit aed23aa

Browse files
skaslevTheGreatCabbage
authored andcommitted
Consistently use _fileno() throughout
1 parent d4b3dd7 commit aed23aa

File tree

2 files changed

+4
-30
lines changed

2 files changed

+4
-30
lines changed

qasync/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ def _add_writer(self, fd, callback, *args):
539539
existing.activated["int"].disconnect()
540540
# will get overwritten by the assignment below anyways
541541

542-
notifier = QtCore.QSocketNotifier(fd, QtCore.QSocketNotifier.Type.Write)
542+
notifier = QtCore.QSocketNotifier(_fileno(fd), QtCore.QSocketNotifier.Type.Write)
543543
notifier.setEnabled(True)
544544
self.__log_debug("Adding writer callback for file descriptor %s", fd)
545545
notifier.activated["int"].connect(

qasync/_unix.py

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,13 @@
99
import selectors
1010
import collections
1111

12-
from . import QtCore, with_logger
12+
from . import QtCore, with_logger, _fileno
1313

1414

1515
EVENT_READ = (1 << 0)
1616
EVENT_WRITE = (1 << 1)
1717

1818

19-
def _fileobj_to_fd(fileobj):
20-
"""
21-
Return a file descriptor from a file object.
22-
23-
Parameters:
24-
fileobj -- file object or file descriptor
25-
26-
Returns:
27-
corresponding file descriptor
28-
29-
Raises:
30-
ValueError if the object is invalid
31-
32-
"""
33-
if isinstance(fileobj, int):
34-
fd = fileobj
35-
else:
36-
try:
37-
fd = int(fileobj.fileno())
38-
except (AttributeError, TypeError, ValueError) as ex:
39-
raise ValueError("Invalid file object: {!r}".format(fileobj)) from ex
40-
if fd < 0:
41-
raise ValueError("Invalid file descriptor: {}".format(fd))
42-
return fd
43-
44-
4519
class _SelectorMapping(collections.abc.Mapping):
4620

4721
"""Mapping of file objects to selector keys."""
@@ -81,14 +55,14 @@ def select(self, *args, **kwargs):
8155
def _fileobj_lookup(self, fileobj):
8256
"""Return a file descriptor from a file object.
8357
84-
This wraps _fileobj_to_fd() to do an exhaustive search in case
58+
This wraps _fileno() to do an exhaustive search in case
8559
the object is invalid but we still have it in our map. This
8660
is used by unregister() so we can unregister an object that
8761
was previously registered even if it is closed. It is also
8862
used by _SelectorMapping.
8963
"""
9064
try:
91-
return _fileobj_to_fd(fileobj)
65+
return _fileno(fileobj)
9266
except ValueError:
9367
# Do an exhaustive search.
9468
for key in self._fd_to_key.values():

0 commit comments

Comments
 (0)