mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-01 23:08:43 +01:00
fix PathInfo instantiation in Python 3.12 (#10328)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
import pathlib
|
||||
import posixpath
|
||||
import sys
|
||||
from typing import Callable, ClassVar
|
||||
from urllib.parse import urlparse
|
||||
|
||||
@@ -27,12 +28,13 @@ class PathInfo(pathlib.PurePath, _BasePath):
|
||||
__slots__ = ()
|
||||
scheme = "local"
|
||||
|
||||
def __new__(cls, *args):
|
||||
# Construct a proper subclass depending on current os
|
||||
if cls is PathInfo:
|
||||
cls = WindowsPathInfo if os.name == "nt" else PosixPathInfo
|
||||
if sys.version_info < (3, 12):
|
||||
|
||||
return cls._from_parts(args) # type: ignore[attr-defined]
|
||||
def __new__(cls, *args):
|
||||
if cls is PathInfo:
|
||||
cls = WindowsPathInfo if os.name == "nt" else PosixPathInfo
|
||||
|
||||
return cls._from_parts(args) # type: ignore[attr-defined]
|
||||
|
||||
def as_posix(self):
|
||||
f = self._flavour # type: ignore[attr-defined]
|
||||
@@ -67,7 +69,7 @@ class PathInfo(pathlib.PurePath, _BasePath):
|
||||
|
||||
def isin(self, other):
|
||||
if isinstance(other, (str, bytes)):
|
||||
other = self.__class__(other)
|
||||
other = self.__class__(other) # type: ignore[arg-type]
|
||||
elif self.__class__ != other.__class__:
|
||||
return False
|
||||
# Use cached casefolded parts to compare paths
|
||||
|
||||
@@ -67,13 +67,12 @@ class TmpDir(pathlib.Path):
|
||||
def config(self):
|
||||
return {"url": self.url}
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
if cls is TmpDir:
|
||||
cls = WindowsTmpDir if os.name == "nt" else PosixTmpDir
|
||||
if sys.version_info < (3, 12):
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
if cls is TmpDir:
|
||||
cls = WindowsTmpDir if os.name == "nt" else PosixTmpDir
|
||||
|
||||
if sys.version_info >= (3, 12):
|
||||
return object.__new__(cls)
|
||||
else: # noqa: RET505
|
||||
# init parameter and `_init` method has been removed in Python 3.10.
|
||||
kw = {"init": False} if sys.version_info < (3, 10) else {}
|
||||
self = cls._from_parts(args, **kw) # type: ignore[attr-defined]
|
||||
|
||||
Reference in New Issue
Block a user