From bd6332a4227b78f1b4f71ade75bec984aeecc9a3 Mon Sep 17 00:00:00 2001 From: barneygale Date: Tue, 17 Dec 2024 14:57:02 +0000 Subject: [PATCH] Optimise Windows implementation a bit --- Lib/pathlib/_local.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Lib/pathlib/_local.py b/Lib/pathlib/_local.py index 8bf0dd7bc21a9e..cb7effa48c0dce 100644 --- a/Lib/pathlib/_local.py +++ b/Lib/pathlib/_local.py @@ -92,8 +92,12 @@ def exists(self, *, follow_symlinks=True): try: return self._exists except AttributeError: - self._exists = os.path.exists(self) - return self._exists + if os.path.exists(self): + self._exists = True + return True + else: + self._exists = self._is_dir = self._is_file = False + return False def is_dir(self, *, follow_symlinks=True): """Whether this path is a directory.""" @@ -102,8 +106,12 @@ def is_dir(self, *, follow_symlinks=True): try: return self._is_dir except AttributeError: - self._is_dir = os.path.isdir(self) - return self._is_dir + if os.path.isdir(self): + self._is_dir = self._exists = True + return True + else: + self._is_dir = False + return False def is_file(self, *, follow_symlinks=True): """Whether this path is a regular file.""" @@ -112,8 +120,12 @@ def is_file(self, *, follow_symlinks=True): try: return self._is_file except AttributeError: - self._is_file = os.path.isfile(self) - return self._is_file + if os.path.isfile(self): + self._is_file = self._exists = True + return True + else: + self._is_file = False + return False def is_symlink(self): """Whether this path is a symbolic link."""