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) 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