From c22ca8f50f2bf0d7e1593cb74864240b33b21ecb Mon Sep 17 00:00:00 2001 From: liyang Date: Wed, 20 Nov 2024 12:59:29 +0800 Subject: [PATCH] make lint happy --- megfile/fsspec.py | 8 ++++---- megfile/utils/__init__.py | 5 +++-- tests/test_smart_path.py | 5 ++++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/megfile/fsspec.py b/megfile/fsspec.py index 9df40c16..4b4aeed5 100644 --- a/megfile/fsspec.py +++ b/megfile/fsspec.py @@ -375,7 +375,7 @@ def sync( self.path_without_protocol, dst_path, recursive=True ) - def rename(self, dst_path: PathLike, overwrite: bool = True) -> "BaseFSSpecPath": + def rename(self, dst_path: PathLike, overwrite: bool = True): """ rename file with fsspec @@ -384,7 +384,7 @@ def rename(self, dst_path: PathLike, overwrite: bool = True) -> "BaseFSSpecPath" """ self.filesystem.mv(self.path_without_protocol, dst_path, recursive=False) - def move(self, dst_path: PathLike, overwrite: bool = True) -> "BaseFSSpecPath": + def move(self, dst_path: PathLike, overwrite: bool = True): """ move file/directory with fsspec @@ -393,7 +393,7 @@ def move(self, dst_path: PathLike, overwrite: bool = True) -> "BaseFSSpecPath": """ self.filesystem.mv(self.path_without_protocol, dst_path, recursive=True) - def unlink(self, missing_ok: bool = False) -> None: + def unlink(self, missing_ok: bool = False): """ Remove the file with fsspec @@ -403,7 +403,7 @@ def unlink(self, missing_ok: bool = False) -> None: return self.filesystem.rm(self.path_without_protocol, recursive=False) - def remove(self, missing_ok: bool = False) -> None: + def remove(self, missing_ok: bool = False): """ Remove the file or directory with fsspec diff --git a/megfile/utils/__init__.py b/megfile/utils/__init__.py index f43477d3..acb6c584 100644 --- a/megfile/utils/__init__.py +++ b/megfile/utils/__init__.py @@ -339,12 +339,13 @@ def __get__( # pyre-ignore[14] "__set_name__ on it." ) with self.lock: + name: str = self.attrname # pyre-ignore[9] # check if another thread filled cache while we awaited lock # cannot use getattr since it will cause RecursionError - val = cls.__dict__[self.attrname] + val = getattr(cls, name) if val is self: val = self.func(cls) - setattr(cls, self.attrname, val) + setattr(cls, name, val) return val diff --git a/tests/test_smart_path.py b/tests/test_smart_path.py index 51b93607..4817f9f8 100644 --- a/tests/test_smart_path.py +++ b/tests/test_smart_path.py @@ -11,6 +11,7 @@ ProtocolNotFoundError, ) from megfile.fs_path import FSPath +from megfile.hf_path import HFPath from megfile.hdfs_path import HdfsPath from megfile.http_path import HttpPath, HttpsPath from megfile.interfaces import Access @@ -58,7 +59,7 @@ def s3_empty_client(mocker): def test_register_result(): - assert len(SmartPath._registered_protocols) == 7 + assert len(SmartPath._registered_protocols) == 8 assert S3Path.protocol in SmartPath._registered_protocols assert FSPath.protocol in SmartPath._registered_protocols assert HttpPath.protocol in SmartPath._registered_protocols @@ -66,6 +67,7 @@ def test_register_result(): assert StdioPath.protocol in SmartPath._registered_protocols assert SftpPath.protocol in SmartPath._registered_protocols assert HdfsPath.protocol in SmartPath._registered_protocols + assert HFPath.protocol in SmartPath._registered_protocols assert SmartPath._registered_protocols[S3Path.protocol] == S3Path assert SmartPath._registered_protocols[FSPath.protocol] == FSPath @@ -73,6 +75,7 @@ def test_register_result(): assert SmartPath._registered_protocols[HttpsPath.protocol] == HttpsPath assert SmartPath._registered_protocols[StdioPath.protocol] == StdioPath assert SmartPath._registered_protocols[HdfsPath.protocol] == HdfsPath + assert SmartPath._registered_protocols[HFPath.protocol] == HFPath assert SmartPath.from_uri(FS_TEST_ABSOLUTE_PATH) == SmartPath(FS_TEST_ABSOLUTE_PATH)