From df62b5eae85fecba70a8f53523964b3a7a5c45d3 Mon Sep 17 00:00:00 2001 From: Andreas Poehlmann Date: Sun, 28 Dec 2025 13:32:52 +0100 Subject: [PATCH] upath.core: handover cached fs instances in with_segments --- upath/core.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/upath/core.py b/upath/core.py index 72017bc1..90ac7fef 100644 --- a/upath/core.py +++ b/upath/core.py @@ -785,7 +785,7 @@ class UPath(_UPathMixin, WritablePath, ReadablePath): if TYPE_CHECKING: # noqa: C901 _chain: Chain _chain_parser: FSSpecChainParser - _fs_cached: bool + _fs_cached: AbstractFileSystem _raw_urlpaths: Sequence[JoinablePathLike] _relative_base: str | None @@ -965,6 +965,8 @@ def with_segments(self, *pathsegments: JoinablePathLike) -> Self: protocol=self._protocol, **self._storage_options, ) + if hasattr(self, "_fs_cached"): + new_instance._fs_cached = self._fs_cached if is_relative: new_instance._relative_base = self._relative_base