Cast the `file` argument, which may be either a string or a Path object, to a Path object. If `file` is neither a string nor a Path object, None will be returned.
(file: Union[str, Path])
| 185 | |
| 186 | |
| 187 | def as_path_object(file: Union[str, Path]) -> Union[Path, None]: |
| 188 | """ |
| 189 | Cast the `file` argument, which may be either a string or a Path object, |
| 190 | to a Path object. |
| 191 | If `file` is neither a string nor a Path object, None will be returned. |
| 192 | """ |
| 193 | if isinstance(file, str): |
| 194 | # Use the standard Path constructor to make a pathlib object. |
| 195 | path = Path(file) |
| 196 | elif isinstance(file, Path): |
| 197 | # `file` is already a Path object. |
| 198 | path = file |
| 199 | else: |
| 200 | # We could not make a Path object out of file. Either `file` is an open file |
| 201 | # descriptor with a `write()` method or it's an invalid object. |
| 202 | path = None |
| 203 | return path |
| 204 | |
| 205 | |
| 206 | def infer_format(path: Union[Path, None], format: Union[str, None]) -> Union[str, None]: |
no outgoing calls
no test coverage detected