diff --git a/Lib/pathlib.py b/Lib/pathlib.py index 89dffa5561a7a5..e3ef2d819fadeb 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 d3fd4bd9e6b7ef..268f4fa394e65c 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 00000000000000..d363eb12f7c386 --- /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