Coverage for /run/media/veganeco/water/status600.com/pypi/reptilian_climates/modules_series_2/ships/fields/gardens_pip/rich/_fileno.py: 30%

1 from __future__ import annotations

2

3 from typing import IO, Callable

4

5

6 def get_fileno(file_like: IO[str]) -> int | None:

7 """Get fileno() from a file, accounting for poorly implemented file-like objects.

8

9 Args:

10 file_like (IO): A file-like object.

11

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