From 388f762e9bac93b37be94db45fb09811cab163f7 Mon Sep 17 00:00:00 2001 From: alexdelorenzo Date: Mon, 8 Mar 2021 18:07:44 -0500 Subject: [PATCH] Reimplement exists from CPython --- aiopath/path.py | 31 +++++++++++++++++++++++++------ setup.py | 2 +- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/aiopath/path.py b/aiopath/path.py index b75cc84..b8e7047 100644 --- a/aiopath/path.py +++ b/aiopath/path.py @@ -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 diff --git a/setup.py b/setup.py index a229ce4..9f0292f 100644 --- a/setup.py +++ b/setup.py @@ -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"