Fix pathlib version conflict

This commit is contained in:
László Károlyi 2024-11-26 19:18:38 +01:00
parent d231505686
commit 7e01745d91
Signed by: karolyi
GPG key ID: 2DCAF25E55735BFE

View file

@ -9,7 +9,7 @@ from pathlib import PosixPath as PosixPathBase
from pathlib import WindowsPath as WindowsPathBase
from platform import system
from threading import RLock
from typing import Iterable
from typing import Callable, Iterable
_UMASK_LOCK = RLock()
_CODE_OSERROR_DIRECTORY_NOT_EMPTY = 66 if system() == 'FreeBSD' else 39
@ -19,6 +19,17 @@ _LOGGER = getLogger(name=__name__)
class Path(PathBase):
'Extending the built-in `Path`.'
def __new__(cls, *args: str, **kwargs: str):
if cls is Path:
cls = WindowsPath if os_name == 'nt' else PosixPath
if hasattr(cls, '_from_parts'):
cls._from_parts: Callable[[Iterable[str]], WindowsPath | PosixPath]
# version < 3.12
return cls._from_parts(args)
else:
# 3.12 on
return object.__new__(cls)
def _ensure_parentdirs_inner(
self, relative_path: Path, mode: int | None = None,
uid: int | None = None, gid: int | None = None) -> Path: