From 65eb882f3862ce126baa59e3a34f36b00bd5127a Mon Sep 17 00:00:00 2001 From: Josh Schneier Date: Fri, 25 Aug 2023 20:21:52 -0400 Subject: [PATCH] [general] add support for pathlib.PurePath to clean_name (#1278) Co-authored-by: Tom Andersen --- storages/utils.py | 4 ++-- tests/test_utils.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/storages/utils.py b/storages/utils.py index 1a9753e14..a44c524c9 100644 --- a/storages/utils.py +++ b/storages/utils.py @@ -34,9 +34,9 @@ def clean_name(name): Normalize the name. Includes cleaning up Windows style paths, ensuring an ending trailing slash, - and coercing from pathlib.Path. + and coercing from pathlib.PurePath. """ - if isinstance(name, pathlib.Path): + if isinstance(name, pathlib.PurePath): name = str(name) # Normalize Windows style paths diff --git a/tests/test_utils.py b/tests/test_utils.py index 252795037..b60827652 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -26,6 +26,9 @@ def test_clean_name_pathlib(self): path = pathlib.Path("path/to/anywhere") self.assertEqual(utils.clean_name(path), "path/to/anywhere") + path = pathlib.PurePath("path/to/anywhere") + self.assertEqual(utils.clean_name(path), "path/to/anywhere") + def test_clean_name_normalize(self): """ Test the normalization of clean_name