@@ -123,28 +123,28 @@ class UPath(pathlib.Path, PureUPath, metaclass=UPathMeta):
123123 _default_accessor = _FSSpecAccessor
124124
125125 def __new__ (cls , * args , ** kwargs ):
126- if len (args ) == 1 and isinstance (args [0 ], cls ):
127- other = args [0 ]
128- new_args = (
129- other ._format_parsed_parts (
130- other ._drv , other ._root , other ._parts
131- ),
132- )
133- new_kwargs = {}
134- if hasattr (other , "_kwargs" ):
135- new_kwargs = other ._kwargs .copy ()
126+ if issubclass (cls , UPath ):
127+ args_list = list (args )
128+ first = args_list .pop (0 )
129+ if isinstance (first , pathlib .PurePath ):
130+ # Create a (modified) copy, if first arg is a Path object
131+ other = first
132+ parts = args_list
133+ drv , root , parts = other ._parse_args (parts )
134+ drv , root , parts = other ._flavour .join_parsed_parts (
135+ other ._drv , other ._root , other ._parts , drv , root , parts
136+ )
137+
138+ new_kwargs = getattr (other , "_kwargs" , {}).copy ()
136139 new_kwargs .pop ("_url" , None )
140+ new_kwargs .update (kwargs )
137141
138- return cls .__new__ (
139- cls ,
140- * new_args ,
141- ** new_kwargs ,
142- )
142+ return other .__class__ (
143+ other ._format_parsed_parts (drv , root , parts ),
144+ ** new_kwargs ,
145+ )
143146
144- if issubclass (cls , UPath ):
145- args_list = list (args )
146- url = args_list .pop (0 )
147- url = stringify_path (url )
147+ url = stringify_path (first )
148148 parsed_url = urllib .parse .urlparse (url )
149149 for key in ["scheme" , "netloc" ]:
150150 val = kwargs .get (key )
0 commit comments