Skip to content

Commit

Permalink
add T_PATH_ARG and remove six from requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
MacHu-GWU committed Dec 20, 2023
1 parent e23540a commit c8dcd34
Show file tree
Hide file tree
Showing 7 changed files with 1,033 additions and 5 deletions.
1 change: 1 addition & 0 deletions pathlib_mate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
WindowsPath,
PosixPath,
PathCls,
T_PATH_ARG,
)
except ImportError as e: # pragma: no cover
pass
Expand Down
1 change: 1 addition & 0 deletions pathlib_mate/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
from .pathlib2 import WindowsPath
from .pathlib2 import PosixPath
from .pathlib2 import PathCls
from .pathlib2 import T_PATH_ARG
13 changes: 10 additions & 3 deletions pathlib_mate/pathlib2.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
TypeVar, Type, Union, Text, Tuple, List, Any, Callable, Iterable, Optional
)

import six
from .vendor import six
import sys

from errno import EINVAL, ENOENT, ENOTDIR, EBADF
Expand Down Expand Up @@ -1354,7 +1354,7 @@ class Path(
)

def __new__(cls, *args, **kwargs):
# type: (Type[Path], *Union[Text, PurePath], **Any) -> Path
# type: (Type[Path], *Union[Text, PurePath, "PathlibPath"], **Any) -> Path
if cls is Path:
cls = WindowsPath if os.name == 'nt' else PosixPath
self = cls._from_parts(args, init=False)
Expand Down Expand Up @@ -1908,5 +1908,12 @@ def is_mount(self):
raise NotImplementedError(
"Path.is_mount() is unsupported on this system")

# An explicitly defined Path class for the current OS. This is more explicit for type hint
PathCls: Union[Type[WindowsPath], Type[PosixPath]] = WindowsPath if os.name == "nt" else PosixPath

PathCls = WindowsPath if os.name == "nt" else PosixPath
# T_PATH_ARG is a path liked object that can be passed into a function,
# you can safely use ``Path(a_path_arg)`` to convert it to a pathlib_mate.Path object
# or safely use ``PathlibPath(a_path_arg)`` to convert it to a pathlib.Path object.
from pathlib import Path as PathlibPath

T_PATH_ARG = Union[str, PathlibPath, Path]

0 comments on commit c8dcd34

Please sign in to comment.