From 352c1060fc2a685df70b284e61fe506098c16ed0 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 12 Dec 2018 12:10:50 -0800 Subject: [PATCH 1/2] Fix for bpo35306: handle '*' in pathlib.Path functions on Windows --- Lib/pathlib.py | 5 +++-- Lib/test/test_pathlib.py | 3 +++ .../next/Library/2018-12-12-12-09-27.bpo-35306.AzA3I6.rst | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2018-12-12-12-09-27.bpo-35306.AzA3I6.rst diff --git a/Lib/pathlib.py b/Lib/pathlib.py index 89dffa5561a7a5c..9396bb61fc3ae4a 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -34,8 +34,9 @@ # Internals # -# EBADF - guard agains macOS `stat` throwing EBADF -_IGNORED_ERROS = (ENOENT, ENOTDIR, EBADF) +# EBADF - guard against macOS `stat` throwing EBADF +# EINVAL - `stat` on Windows throws it for invalid paths +_IGNORED_ERROS = (ENOENT, ENOTDIR, EBADF, EINVAL) def _is_wildcard_pattern(pat): # Whether this pattern needs actual matching using fnmatch, or can diff --git a/Lib/test/test_pathlib.py b/Lib/test/test_pathlib.py index d3fd4bd9e6b7efd..268f4fa394e65ca 100644 --- a/Lib/test/test_pathlib.py +++ b/Lib/test/test_pathlib.py @@ -2242,6 +2242,9 @@ def test_rglob(self): p = P(BASE, "dirC") self.assertEqual(set(p.rglob("FILEd")), { P(BASE, "dirC/dirD/fileD") }) + def test_exists_for_invalid_path(self): + self.assertEqual(self.cls("*").exists(), False) + def test_expanduser(self): P = self.cls with support.EnvironmentVarGuard() as env: diff --git a/Misc/NEWS.d/next/Library/2018-12-12-12-09-27.bpo-35306.AzA3I6.rst b/Misc/NEWS.d/next/Library/2018-12-12-12-09-27.bpo-35306.AzA3I6.rst new file mode 100644 index 000000000000000..d363eb12f7c3866 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-12-12-12-09-27.bpo-35306.AzA3I6.rst @@ -0,0 +1 @@ +Handle '*' in pathlib.Path.exists on Windows From 846e7010a4afaff6681dd3d3a199f405ffe43f07 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Wed, 12 Dec 2018 12:26:07 -0800 Subject: [PATCH 2/2] drop trailing whitespace --- Lib/pathlib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/pathlib.py b/Lib/pathlib.py index 9396bb61fc3ae4a..e3ef2d819fadeb0 100644 --- a/Lib/pathlib.py +++ b/Lib/pathlib.py @@ -35,7 +35,7 @@ # # EBADF - guard against macOS `stat` throwing EBADF -# EINVAL - `stat` on Windows throws it for invalid paths +# EINVAL - `stat` on Windows throws it for invalid paths _IGNORED_ERROS = (ENOENT, ENOTDIR, EBADF, EINVAL) def _is_wildcard_pattern(pat):