From 9af784b3653b5fd5166bc7ddb91d00e1c310f399 Mon Sep 17 00:00:00 2001 From: Andreas Poehlmann Date: Fri, 26 Dec 2025 20:03:39 +0100 Subject: [PATCH 1/2] upath.core: raise UnsupportedOperation if touch not implemented --- upath/core.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/upath/core.py b/upath/core.py index a8a72669..c4885cd1 100644 --- a/upath/core.py +++ b/upath/core.py @@ -1754,13 +1754,16 @@ def touch(self, mode: int = 0o666, exist_ok: bool = True) -> None: exists = self.fs.exists(self.path) if exists and not exist_ok: raise FileExistsError(str(self)) - if not exists: - self.fs.touch(self.path, truncate=True) - else: - try: - self.fs.touch(self.path, truncate=False) - except (NotImplementedError, ValueError): - pass # unsupported by filesystem + try: + if not exists: + self.fs.touch(self.path, truncate=True) + else: + try: + self.fs.touch(self.path, truncate=False) + except ValueError: + pass # unsupported by filesystem + except NotImplementedError: + _raise_unsupported(type(self).__name__, "touch") def lchmod(self, mode: int) -> None: _raise_unsupported(type(self).__name__, "lchmod") From 41524961422e078d4e3fa1ac65ca1aab0d18a5fd Mon Sep 17 00:00:00 2001 From: Andreas Poehlmann Date: Sun, 28 Dec 2025 10:54:06 +0100 Subject: [PATCH 2/2] upath.core: adjust touch error handling --- upath/core.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/upath/core.py b/upath/core.py index c4885cd1..72017bc1 100644 --- a/upath/core.py +++ b/upath/core.py @@ -1754,16 +1754,16 @@ def touch(self, mode: int = 0o666, exist_ok: bool = True) -> None: exists = self.fs.exists(self.path) if exists and not exist_ok: raise FileExistsError(str(self)) - try: - if not exists: + if not exists: + try: self.fs.touch(self.path, truncate=True) - else: - try: - self.fs.touch(self.path, truncate=False) - except ValueError: - pass # unsupported by filesystem - except NotImplementedError: - _raise_unsupported(type(self).__name__, "touch") + except NotImplementedError: + _raise_unsupported(type(self).__name__, "touch") + else: + try: + self.fs.touch(self.path, truncate=False) + except (NotImplementedError, ValueError): + pass # unsupported by filesystem def lchmod(self, mode: int) -> None: _raise_unsupported(type(self).__name__, "lchmod")