Cleanly determine whether ``stream`` has a useful ``.fileno()``. .. note:: This function helps determine if a given file-like object can be used with various terminal-oriented modules and functions such as `select`, `termios`, and `tty`. For most of those, a fileno
(stream: IO)
| 71 | |
| 72 | |
| 73 | def has_fileno(stream: IO) -> bool: |
| 74 | """ |
| 75 | Cleanly determine whether ``stream`` has a useful ``.fileno()``. |
| 76 | |
| 77 | .. note:: |
| 78 | This function helps determine if a given file-like object can be used |
| 79 | with various terminal-oriented modules and functions such as `select`, |
| 80 | `termios`, and `tty`. For most of those, a fileno is all that is |
| 81 | required; they'll function even if ``stream.isatty()`` is ``False``. |
| 82 | |
| 83 | :param stream: A file-like object. |
| 84 | |
| 85 | :returns: |
| 86 | ``True`` if ``stream.fileno()`` returns an integer, ``False`` otherwise |
| 87 | (this includes when ``stream`` lacks a ``fileno`` method). |
| 88 | |
| 89 | .. versionadded:: 1.0 |
| 90 | """ |
| 91 | try: |
| 92 | return isinstance(stream.fileno(), int) |
| 93 | except (AttributeError, io.UnsupportedOperation): |
| 94 | return False |
| 95 | |
| 96 | |
| 97 | def isatty(stream: IO) -> Union[bool, Any]: |
no outgoing calls
no test coverage detected
searching dependent graphs…