Skip to content

Commit

Permalink
Optimise Windows implementation a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
barneygale committed Dec 17, 2024
1 parent 592603b commit bd6332a
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions Lib/pathlib/_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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."""
Expand All @@ -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."""
Expand Down

0 comments on commit bd6332a

Please sign in to comment.