Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes _kwargs in local sub paths #158

Merged
merged 4 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions upath/implementations/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,22 @@ def _from_parts(cls, args, *, url=None, **kw):
obj._url = SplitResult("", "", str(obj), "", "")
return obj

@classmethod
def _from_parsed_parts(
cls,
drv,
root,
parts,
url=None,
**kwargs: Any,
):
obj = super(UPath, cls)._from_parsed_parts( # type: ignore[misc]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure why mypy complained here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure either. Especially since it didn't complain with _from_parts...

drv, root, parts
)
obj._kwargs = {}
obj._url = SplitResult("", "", str(obj), "", "")
return obj


class WindowsUPath(WindowsPath, UPath):
__slots__ = ()
Expand All @@ -89,3 +105,19 @@ def _from_parts(cls, args, *, url=None, **kw):
obj._kwargs = {}
obj._url = SplitResult("", "", str(obj), "", "")
return obj

@classmethod
def _from_parsed_parts(
cls,
drv,
root,
parts,
url=None,
**kwargs: Any,
):
obj = super(UPath, cls)._from_parsed_parts( # type: ignore[misc]
drv, root, parts
)
obj._kwargs = {}
obj._url = SplitResult("", "", str(obj), "", "")
return obj
5 changes: 5 additions & 0 deletions upath/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ def test_access_to_private_kwargs_and_url(urlpath):
assert isinstance(pth._url, SplitResult)
assert pth._url.scheme == "" or pth._url.scheme in pth.fs.protocol
assert pth._url.path == pth.path
subpth = pth / "foo"
assert subpth._kwargs == {}
assert isinstance(subpth._url, SplitResult)
assert subpth._url.scheme == "" or subpth._url.scheme in subpth.fs.protocol
assert subpth._url.path == subpth.path


def test_copy_path_append_kwargs():
Expand Down