From f7529325e0739a0c818f84d50b9642b30918407f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20=C5=A0a=C5=A1ko?= Date: Fri, 6 Oct 2023 15:49:36 +0200 Subject: [PATCH] Hide `CommitOperationAdd`'s internal attributes (#1716) * Hide `CommitOperationAdd`'s internal attributes * Update src/huggingface_hub/_commit_api.py Co-authored-by: Lucain * Style --------- Co-authored-by: Lucain --- src/huggingface_hub/_commit_api.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/huggingface_hub/_commit_api.py b/src/huggingface_hub/_commit_api.py index 8ee9d551cc..bdf481e265 100644 --- a/src/huggingface_hub/_commit_api.py +++ b/src/huggingface_hub/_commit_api.py @@ -137,22 +137,18 @@ 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: 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 + _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)