Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/rich/_fileno.py: 30%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from __future__ import annotations
3from typing import IO, Callable
6def get_fileno(file_like: IO[str]) -> int | None:
7 """Get fileno() from a file, accounting for poorly implemented file-like objects.
9 Args:
10 file_like (IO): A file-like object.
12 Returns:
13 int | None: The result of fileno if available, or None if operation failed.
14 """
15 fileno: Callable[[], int] | None = getattr(file_like, "fileno", None)
16 if fileno is not None:
17 try:
18 return fileno()
19 except Exception:
20 # `fileno` is documented as potentially raising a OSError
21 # Alas, from the issues, there are so many poorly implemented file-like objects,
22 # that `fileno()` can raise just about anything.
23 return None
24 return None