From e5996f7a6c5223425da03c6c6dfe9bcc8eaa9211 Mon Sep 17 00:00:00 2001 From: Theodore Chang Date: Fri, 29 May 2026 12:29:33 +0200 Subject: [PATCH 1/2] Enhance rmdir method to warn about future behavior change and adjust recursive handling --- upath/implementations/local.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/upath/implementations/local.py b/upath/implementations/local.py index 884199d9..fb6289e7 100644 --- a/upath/implementations/local.py +++ b/upath/implementations/local.py @@ -362,10 +362,13 @@ def open( ) def rmdir(self, recursive: bool = UNSET_DEFAULT) -> None: - if recursive is UNSET_DEFAULT or not recursive: - return super().rmdir() - else: - shutil.rmtree(self) + if recursive is UNSET_DEFAULT: + warnings.warn( + "This function will change behavior in a future version.", FutureWarning + ) + recursive = True + + return shutil.rmtree(self) if recursive else super().rmdir() # we need to override pathlib.Path._copy_from to support it as a # WritablePath._copy_from target with support for on_name_collision From f8e23487f8260c959f4221d6bb41678de0c02772 Mon Sep 17 00:00:00 2001 From: Theodore Chang Date: Fri, 29 May 2026 12:35:41 +0200 Subject: [PATCH 2/2] Refactor rmdir method to use UNSET_DEFAULT for recursive parameter and add warning for future behavior change --- upath/core.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/upath/core.py b/upath/core.py index 90ebac60..18261d18 100644 --- a/upath/core.py +++ b/upath/core.py @@ -1880,7 +1880,7 @@ def unlink(self, missing_ok: bool = False) -> None: return self.fs.rm(self.path, recursive=False) - def rmdir(self, recursive: bool = True) -> None: # fixme: non-standard + def rmdir(self, recursive: bool = UNSET_DEFAULT) -> None: # fixme: non-standard """ Remove this directory. @@ -1896,7 +1896,18 @@ def rmdir(self, recursive: bool = True) -> None: # fixme: non-standard """ if not self.is_dir(): raise NotADirectoryError(str(self)) - if not recursive and next(self.iterdir()): # type: ignore[arg-type] + + has_contents = bool(next(self.iterdir())) + + if recursive is UNSET_DEFAULT: + if has_contents: + warnings.warn( + "This function will change behavior in a future version.", + FutureWarning, + ) + recursive = True + + if not recursive and has_contents: raise OSError(f"Not recursive and directory not empty: {self}") self.fs.rm(self.path, recursive=recursive)