Skip to content

Commit

Permalink
Reimplement exists from CPython
Browse files Browse the repository at this point in the history
  • Loading branch information
alexdelorenzo committed Mar 8, 2021
1 parent 531ee16 commit 388f762
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
31 changes: 25 additions & 6 deletions aiopath/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,18 +330,37 @@ async def symlink_to(self, target: str, target_is_directory: bool = False):
await self._accessor.symlink(target, self, target_is_directory)

async def exists(self) -> bool:
"""
Whether this path exists.
"""
try:
async with async_open(self._path, 'rb'):
pass
await self.stat()

return True
except OSError as e:
if not _ignore_error(e):
raise

except IsADirectoryError:
return True
return False

except FileNotFoundError:
except ValueError:
# Non-encodable path
return False

return True

#async def exists(self) -> bool:
#try:
#async with async_open(self._path, 'rb'):
#pass

#return True

#except IsADirectoryError:
#return True

#except FileNotFoundError:
#return False

@classmethod
async def cwd(cls: type) -> str:
"""Return a new path pointing to the current working directory
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

PKG_NAME = "aiopath"
NAME = 'aiopath'
VERSION = "0.1.2"
VERSION = "0.2.0"
LICENSE = "LGPL-3.0"

DESC = "📁 Async pathlib for Python"
Expand Down

0 comments on commit 388f762

Please sign in to comment.