-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
18 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,32 @@ | ||
from __future__ import annotations | ||
|
||
import os | ||
import sys | ||
from pathlib import Path | ||
from typing import Any, NoReturn | ||
|
||
if sys.version_info >= (3, 10): | ||
from typing import TypeGuard | ||
else: | ||
from typing_extensions import TypeGuard | ||
|
||
def is_path(f): | ||
|
||
def is_path(f: Any) -> TypeGuard[bytes | str | Path]: | ||
return isinstance(f, (bytes, str, Path)) | ||
|
||
|
||
def is_directory(f): | ||
def is_directory(f: Any) -> TypeGuard[bytes | str | Path]: | ||
"""Checks if an object is a string, and that it points to a directory.""" | ||
return is_path(f) and os.path.isdir(f) | ||
|
||
|
||
class DeferredError: | ||
def __init__(self, ex): | ||
def __init__(self, ex: BaseException): | ||
self.ex = ex | ||
|
||
def __getattr__(self, elt): | ||
def __getattr__(self, elt: str) -> NoReturn: | ||
raise self.ex | ||
|
||
@staticmethod | ||
def new(ex: BaseException) -> Any: | ||
return DeferredError(ex) |