Some Traversables implement ``is_dir()`` to raise an exception (i.e. ``FileNotFoundError``) when the directory doesn't exist. This function wraps that call to always return a boolean and only return True if there's a dir and it exists.
(path: Traversable)
| 150 | |
| 151 | |
| 152 | def _is_present_dir(path: Traversable) -> bool: |
| 153 | """ |
| 154 | Some Traversables implement ``is_dir()`` to raise an |
| 155 | exception (i.e. ``FileNotFoundError``) when the |
| 156 | directory doesn't exist. This function wraps that call |
| 157 | to always return a boolean and only return True |
| 158 | if there's a dir and it exists. |
| 159 | """ |
| 160 | with contextlib.suppress(FileNotFoundError): |
| 161 | return path.is_dir() |
| 162 | return False |
| 163 | |
| 164 | |
| 165 | @functools.singledispatch |