Skip to content

copy_into doesn't work for str target_dir #527

@hutch3232

Description

@hutch3232

def copy_into(
self, target_dir: _WT | SupportsPathLike | str, **kwargs: Any
) -> _WT | UPath:

The type hints imply a str should be supported, but I get the following:

# /// script
# requires-python = ">=3.13"
# dependencies = [
#     "dotenv>=0.9.9",
#     "s3fs>=2025.12.0",
#     "universal-pathlib>=0.3.7",
# ]
# ///
import tempfile

from dotenv import load_dotenv
from upath import UPath

load_dotenv()

path = UPath("s3://my-bucket/my-dir/my-file.txt")

with tempfile.TemporaryDirectory() as tmpdir:
    path.copy_into(tmpdir)

# Traceback (most recent call last):
#   File "/mnt/code/upath_copy.py", line 21, in <module>
#     path.copy_into(tmpdir)
#     ~~~~~~~~~~~~~~^^^^^^^^
#   File "/mnt/imported/data/mewtwo/uv/environments-v2/upath-copy-f6a8fa3cfa21e199/lib/python3.13/site-packages/upath/core.py", line 1236, in copy_into
#     return super().copy_into(self.with_segments(target_dir), **kwargs)
#                              ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
#   File "/mnt/imported/data/mewtwo/uv/environments-v2/upath-copy-f6a8fa3cfa21e199/lib/python3.13/site-packages/upath/core.py", line 963, in with_segments
#     new_instance = type(self)(
#         *pathsegments,
#         protocol=self._protocol,
#         **self._storage_options,
#     )
#   File "/mnt/imported/data/mewtwo/uv/environments-v2/upath-copy-f6a8fa3cfa21e199/lib/python3.13/site-packages/upath/core.py", line 152, in __call__
#     inst.__init__(*args, **kwargs)  # type: ignore[misc]
#     ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
#   File "/mnt/imported/data/mewtwo/uv/environments-v2/upath-copy-f6a8fa3cfa21e199/lib/python3.13/site-packages/upath/implementations/cloud.py", line 144, in __init__
#     raise ValueError("non key-like path provided (bucket/container missing)")
# ValueError: non key-like path provided (bucket/container missing)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛Something isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions