From 810f16918d75280f5d7740cc54719c49fbe303a9 Mon Sep 17 00:00:00 2001 From: mariosasko Date: Thu, 5 Oct 2023 18:21:40 +0200 Subject: [PATCH 1/3] Hide `CommitOperationAdd`'s internal attributes --- src/huggingface_hub/_commit_api.py | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/huggingface_hub/_commit_api.py b/src/huggingface_hub/_commit_api.py index 8ee9d551cc..765138164e 100644 --- a/src/huggingface_hub/_commit_api.py +++ b/src/huggingface_hub/_commit_api.py @@ -137,22 +137,16 @@ class CommitOperationAdd: upload_info: UploadInfo = field(init=False, repr=False) # Internal attributes - _upload_mode: Optional[UploadMode] = None # set to "lfs" or "regular" once known - _is_uploaded: bool = False # set to True once the file has been upload as LFS - _is_committed: bool = False # set to True once the file has been committed + _upload_mode: UploadMode = field(init=False, repr=False) # set to "lfs" or "regular" once known + _is_uploaded: bool = field( + init=False, repr=False, default=False + ) # set to True once the file has been uploaded as LFS + _is_committed: bool = field(init=False, repr=False, default=False) # set to True once the file has been committed def __post_init__(self) -> None: """Validates `path_or_fileobj` and compute `upload_info`.""" self.path_in_repo = _validate_path_in_repo(self.path_in_repo) - # Validate `_is_uploaded` and `_upload_mode` cannot be set by user - if self._is_uploaded is not False: - raise ValueError("Attribute `_is_uploaded` cannot be set manually.") - if self._upload_mode is not None: - raise ValueError("Attribute `_upload_mode` cannot be set manually.") - if self._is_committed is not False: - raise ValueError("Attribute `_is_committed` cannot be set manually.") - # Validate `path_or_fileobj` value if isinstance(self.path_or_fileobj, Path): self.path_or_fileobj = str(self.path_or_fileobj) From c84cea3ee692074945694f18311526d70928b3e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20=C5=A0a=C5=A1ko?= Date: Fri, 6 Oct 2023 15:05:47 +0200 Subject: [PATCH 2/3] Update src/huggingface_hub/_commit_api.py Co-authored-by: Lucain --- src/huggingface_hub/_commit_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/huggingface_hub/_commit_api.py b/src/huggingface_hub/_commit_api.py index 765138164e..e8a6a164ce 100644 --- a/src/huggingface_hub/_commit_api.py +++ b/src/huggingface_hub/_commit_api.py @@ -137,7 +137,7 @@ class CommitOperationAdd: upload_info: UploadInfo = field(init=False, repr=False) # Internal attributes - _upload_mode: UploadMode = field(init=False, repr=False) # set to "lfs" or "regular" once known + _upload_mode: Optional[UploadMode] = field(init=False, repr=False, default=None) # set to "lfs" or "regular" once known _is_uploaded: bool = field( init=False, repr=False, default=False ) # set to True once the file has been uploaded as LFS From 0e67884bb6634e8cf701ef4991ce414e8f60a968 Mon Sep 17 00:00:00 2001 From: mariosasko Date: Fri, 6 Oct 2023 15:08:02 +0200 Subject: [PATCH 3/3] Style --- src/huggingface_hub/_commit_api.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/huggingface_hub/_commit_api.py b/src/huggingface_hub/_commit_api.py index e8a6a164ce..bdf481e265 100644 --- a/src/huggingface_hub/_commit_api.py +++ b/src/huggingface_hub/_commit_api.py @@ -137,7 +137,9 @@ class CommitOperationAdd: upload_info: UploadInfo = field(init=False, repr=False) # Internal attributes - _upload_mode: Optional[UploadMode] = field(init=False, repr=False, default=None) # set to "lfs" or "regular" once known + _upload_mode: Optional[UploadMode] = field( + init=False, repr=False, default=None + ) # set to "lfs" or "regular" once known _is_uploaded: bool = field( init=False, repr=False, default=False ) # set to True once the file has been uploaded as LFS