Skip to content

Commit

Permalink
make linting and tests work on multiple py versions
Browse files Browse the repository at this point in the history
  • Loading branch information
pjbull committed Sep 22, 2023
1 parent b02e4e7 commit fc21d15
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
21 changes: 18 additions & 3 deletions cloudpathlib/cloudpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
PosixPath,
PurePosixPath,
WindowsPath,
_make_selector,
_PathParents,
)

Expand Down Expand Up @@ -46,8 +45,13 @@

if sys.version_info >= (3, 12):
from pathlib import posixpath as _posix_flavour # type: ignore[attr-defined]
from pathlib import _make_selector # type: ignore[attr-defined]

Check warning on line 48 in cloudpathlib/cloudpath.py

View check run for this annotation

Codecov / codecov/patch

cloudpathlib/cloudpath.py#L47-L48

Added lines #L47 - L48 were not covered by tests
else:
from pathlib import _posix_flavour # type: ignore[attr-defined]
from pathlib import _make_selector as _make_selector_pathlib # type: ignore[attr-defined]

def _make_selector(pattern_parts, _flavour, case_sensitive=True):
return _make_selector_pathlib(tuple(pattern_parts), _flavour)


from cloudpathlib.enums import FileCacheMode
Expand Down Expand Up @@ -730,7 +734,13 @@ def relative_to(self, other: Self, walk_up: bool = False) -> PurePosixPath:
raise ValueError(
f"{self} is a {self.cloud_prefix} path, but {other} is a {other.cloud_prefix} path"
)
return self._path.relative_to(other._path, walk_up=walk_up) # type: ignore[call-arg]

kwargs = dict(walk_up=walk_up)

if sys.version_info < (3, 12):
kwargs.pop("walk_up")

return self._path.relative_to(other._path, **kwargs) # type: ignore[call-arg]

def is_relative_to(self, other: Self) -> bool:
try:
Expand All @@ -748,7 +758,12 @@ def match(self, path_pattern: str, case_sensitive: Optional[bool] = None) -> boo
if path_pattern.startswith(self.anchor + self.drive + "/"):
path_pattern = path_pattern[len(self.anchor + self.drive + "/") :]

return self._dispatch_to_path("match", path_pattern, case_sensitive=case_sensitive)
kwargs = dict(case_sensitive=case_sensitive)

if sys.version_info < (3, 12):
kwargs.pop("case_sensitive")

return self._dispatch_to_path("match", path_pattern, **kwargs)

@property
def parent(self) -> Self:
Expand Down
10 changes: 9 additions & 1 deletion tests/test_cloudpath_instantiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ def test_public_interface_is_superset(rig):
# all parameters for Path method should be part of CloudPath signature
for parameter in lp_signature.parameters:
# some parameters like _deprecated in Path.is_relative_to are not really part of the signature
if parameter.startswith("_"):
if parameter.startswith("_") or (
name == "joinpath" and parameter in ["args", "pathsegments"]
): # handle arg name change in 3.12
continue

assert (
Expand All @@ -130,6 +132,12 @@ def test_public_interface_is_superset(rig):

# extra parameters for CloudPath method should be optional with defaults
for parameter, param_details in cp_signature.parameters.items():
if name == "joinpath" and parameter in [
"args",
"pathsegments",
]: # handle arg name change in 3.12
continue

if parameter not in lp_signature.parameters:
assert (
param_details.default is not inspect.Parameter.empty
Expand Down

0 comments on commit fc21d15

Please sign in to comment.