Skip to content

Commit 479d1ed

Browse files
committed
merge
1 parent 4d7be31 commit 479d1ed

File tree

1 file changed

+33
-34
lines changed

1 file changed

+33
-34
lines changed

upath/core.py

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -104,43 +104,42 @@ class UPath(pathlib.Path):
104104
]
105105

106106
def __new__(cls, *args, **kwargs) -> Union["UPath", pathlib.Path]:
107-
if issubclass(cls, UPath):
108-
args_list = list(args)
109-
first = args_list.pop(0)
110-
if isinstance(first, pathlib.PurePath):
111-
# Create a (modified) copy, if first arg is a Path object
112-
other = first
113-
parts = args_list
114-
drv, root, parts = other._parse_args(parts)
115-
drv, root, parts = other._flavour.join_parsed_parts(
116-
other._drv, other._root, other._parts, drv, root, parts
117-
)
107+
args_list = list(args)
108+
first = args_list.pop(0)
109+
if isinstance(first, pathlib.PurePath):
110+
# Create a (modified) copy, if first arg is a Path object
111+
other = first
112+
parts = args_list
113+
drv, root, parts = other._parse_args(parts)
114+
drv, root, parts = other._flavour.join_parsed_parts(
115+
other._drv, other._root, other._parts, drv, root, parts
116+
)
118117

119-
new_kwargs = getattr(other, "_kwargs", {}).copy()
120-
new_kwargs.pop("_url", None)
121-
new_kwargs.update(kwargs)
118+
new_kwargs = getattr(other, "_kwargs", {}).copy()
119+
new_kwargs.pop("_url", None)
120+
new_kwargs.update(kwargs)
122121

123-
return other.__class__(
124-
other._format_parsed_parts(drv, root, parts),
125-
**new_kwargs,
126-
)
122+
return other.__class__(
123+
other._format_parsed_parts(drv, root, parts),
124+
**new_kwargs,
125+
)
126+
127+
url = stringify_path(first)
128+
parsed_url = urllib.parse.urlparse(url)
129+
for key in ["scheme", "netloc"]:
130+
val = kwargs.get(key)
131+
if val:
132+
parsed_url = parsed_url._replace(**{key: val})
133+
134+
fsspec_impls = list(registry) + list(known_implementations.keys())
135+
if parsed_url.scheme and parsed_url.scheme in fsspec_impls:
136+
import upath.registry
137+
138+
cls = upath.registry._registry[parsed_url.scheme]
139+
kwargs["_url"] = parsed_url
140+
args_list.insert(0, parsed_url.path)
141+
return cls._from_parts(tuple(args_list), **kwargs)
127142

128-
url = stringify_path(first)
129-
parsed_url = urllib.parse.urlparse(url)
130-
for key in ["scheme", "netloc"]:
131-
val = kwargs.get(key)
132-
if val:
133-
parsed_url = parsed_url._replace(**{key: val})
134-
135-
fsspec_impls = list(registry) + list(known_implementations.keys())
136-
if parsed_url.scheme and parsed_url.scheme in fsspec_impls:
137-
import upath.registry
138-
139-
cls = upath.registry._registry[parsed_url.scheme]
140-
kwargs["_url"] = parsed_url
141-
args_list.insert(0, parsed_url.path)
142-
args = tuple(args_list)
143-
return cls._from_parts(args, **kwargs)
144143
# treat as local filesystem, return PosixPath or WindowsPath
145144
return pathlib.Path(*args, **kwargs)
146145

0 commit comments

Comments
 (0)