Skip to content

Commit

Permalink
update ruff (#2071)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wauplin authored Mar 1, 2024
1 parent 41ae3a6 commit 485d313
Show file tree
Hide file tree
Showing 54 changed files with 71 additions and 34 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def get_version() -> str:
]

extras["quality"] = [
"ruff>=0.1.3",
"ruff>=0.3.0",
"mypy==1.5.1",
]

Expand Down
1 change: 1 addition & 0 deletions src/huggingface_hub/_commit_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Type definitions and utilities for the `create_commit` API
"""

import base64
import io
import os
Expand Down
1 change: 1 addition & 0 deletions src/huggingface_hub/_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Contains methods to login to the Hub."""

import os
import subprocess
from functools import partial
Expand Down
1 change: 1 addition & 0 deletions src/huggingface_hub/_multi_commits.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Contains utilities to multi-commits (i.e. push changes iteratively on a PR)."""

import re
from dataclasses import dataclass, field
from typing import TYPE_CHECKING, Iterable, List, Optional, Set, Tuple, Union
Expand Down
1 change: 1 addition & 0 deletions src/huggingface_hub/_tensorboard_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Contains a logger to push training logs to the Hub, using Tensorboard."""

from pathlib import Path
from typing import TYPE_CHECKING, List, Optional, Union

Expand Down
1 change: 1 addition & 0 deletions src/huggingface_hub/_webhooks_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Contains data structures to parse the webhooks payload."""

from typing import List, Literal, Optional

from pydantic import BaseModel
Expand Down
1 change: 1 addition & 0 deletions src/huggingface_hub/_webhooks_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Contains `WebhooksServer` and `webhook_endpoint` to create a webhook server easily."""

import atexit
import inspect
import os
Expand Down
1 change: 1 addition & 0 deletions src/huggingface_hub/commands/_cli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Contains a utility for good-looking prints."""

import os
from typing import List, Union

Expand Down
1 change: 1 addition & 0 deletions src/huggingface_hub/commands/delete_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
TODO: add "-y" arg for immediate deletion ?
See discussions in https://github.com/huggingface/huggingface_hub/issues/1025.
"""

import os
from argparse import Namespace, _SubParsersAction
from functools import wraps
Expand Down
1 change: 1 addition & 0 deletions src/huggingface_hub/commands/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
# Download to local dir
huggingface-cli download gpt2 --local-dir=./models/gpt2
"""

import warnings
from argparse import Namespace, _SubParsersAction
from typing import List, Literal, Optional, Union
Expand Down
1 change: 1 addition & 0 deletions src/huggingface_hub/commands/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
Usage:
huggingface-cli env
"""

from argparse import _SubParsersAction

from ..utils import dump_environment_info
Expand Down
1 change: 1 addition & 0 deletions src/huggingface_hub/commands/scan_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
huggingface-cli scan-cache -vvv
huggingface-cli scan-cache --dir ~/.cache/huggingface/hub
"""

import time
from argparse import Namespace, _SubParsersAction
from typing import Optional
Expand Down
1 change: 1 addition & 0 deletions src/huggingface_hub/commands/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
# Schedule commits every 30 minutes
huggingface-cli upload Wauplin/my-cool-model --every=30
"""

import os
import time
import warnings
Expand Down
1 change: 1 addition & 0 deletions src/huggingface_hub/community.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
See [the Discussions and Pull Requests guide](https://huggingface.co/docs/hub/repositories-pull-requests-discussions)
for more information on Pull Requests, Discussions, and the community tab.
"""

from dataclasses import dataclass
from datetime import datetime
from typing import List, Literal, Optional, Union
Expand Down
18 changes: 6 additions & 12 deletions src/huggingface_hub/hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3556,8 +3556,7 @@ def create_commit( # type: ignore
num_threads: int = 5,
parent_commit: Optional[str] = None,
run_as_future: Literal[False] = ...,
) -> CommitInfo:
...
) -> CommitInfo: ...

@overload
def create_commit(
Expand All @@ -3574,8 +3573,7 @@ def create_commit(
num_threads: int = 5,
parent_commit: Optional[str] = None,
run_as_future: Literal[True] = ...,
) -> Future[CommitInfo]:
...
) -> Future[CommitInfo]: ...

@validate_hf_hub_args
@future_compatible
Expand Down Expand Up @@ -4291,8 +4289,7 @@ def upload_file( # type: ignore
create_pr: Optional[bool] = None,
parent_commit: Optional[str] = None,
run_as_future: Literal[False] = ...,
) -> CommitInfo:
...
) -> CommitInfo: ...

@overload
def upload_file(
Expand All @@ -4309,8 +4306,7 @@ def upload_file(
create_pr: Optional[bool] = None,
parent_commit: Optional[str] = None,
run_as_future: Literal[True] = ...,
) -> Future[CommitInfo]:
...
) -> Future[CommitInfo]: ...

@validate_hf_hub_args
@future_compatible
Expand Down Expand Up @@ -4498,8 +4494,7 @@ def upload_folder( # type: ignore
multi_commits: Literal[False] = ...,
multi_commits_verbose: bool = False,
run_as_future: Literal[False] = ...,
) -> CommitInfo:
...
) -> CommitInfo: ...

@overload
def upload_folder( # type: ignore
Expand Down Expand Up @@ -4544,8 +4539,7 @@ def upload_folder( # type: ignore
multi_commits: Literal[False] = ...,
multi_commits_verbose: bool = False,
run_as_future: Literal[True] = ...,
) -> Future[CommitInfo]:
...
) -> Future[CommitInfo]: ...

@overload
def upload_folder(
Expand Down
12 changes: 4 additions & 8 deletions src/huggingface_hub/inference/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1207,8 +1207,7 @@ def text_generation( # type: ignore
truncate: Optional[int] = None,
typical_p: Optional[float] = None,
watermark: bool = False,
) -> str:
...
) -> str: ...

@overload
def text_generation( # type: ignore
Expand All @@ -1231,8 +1230,7 @@ def text_generation( # type: ignore
truncate: Optional[int] = None,
typical_p: Optional[float] = None,
watermark: bool = False,
) -> TextGenerationResponse:
...
) -> TextGenerationResponse: ...

@overload
def text_generation( # type: ignore
Expand All @@ -1255,8 +1253,7 @@ def text_generation( # type: ignore
truncate: Optional[int] = None,
typical_p: Optional[float] = None,
watermark: bool = False,
) -> Iterable[str]:
...
) -> Iterable[str]: ...

@overload
def text_generation(
Expand All @@ -1279,8 +1276,7 @@ def text_generation(
truncate: Optional[int] = None,
typical_p: Optional[float] = None,
watermark: bool = False,
) -> Iterable[TextGenerationStreamResponse]:
...
) -> Iterable[TextGenerationStreamResponse]: ...

def text_generation(
self,
Expand Down
11 changes: 7 additions & 4 deletions src/huggingface_hub/inference/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Contains utilities used by both the sync and async inference clients."""

import base64
import io
import json
Expand Down Expand Up @@ -163,13 +164,15 @@ def _first_or_none(items: List[Any]) -> Optional[Any]:


@overload
def _open_as_binary(content: ContentT) -> ContextManager[BinaryT]:
... # means "if input is not None, output is not None"
def _open_as_binary(
content: ContentT,
) -> ContextManager[BinaryT]: ... # means "if input is not None, output is not None"


@overload
def _open_as_binary(content: Literal[None]) -> ContextManager[Literal[None]]:
... # means "if input is None, output is None"
def _open_as_binary(
content: Literal[None],
) -> ContextManager[Literal[None]]: ... # means "if input is None, output is None"


@contextmanager # type: ignore
Expand Down
12 changes: 4 additions & 8 deletions src/huggingface_hub/inference/_generated/_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1230,8 +1230,7 @@ async def text_generation( # type: ignore
truncate: Optional[int] = None,
typical_p: Optional[float] = None,
watermark: bool = False,
) -> str:
...
) -> str: ...

@overload
async def text_generation( # type: ignore
Expand All @@ -1254,8 +1253,7 @@ async def text_generation( # type: ignore
truncate: Optional[int] = None,
typical_p: Optional[float] = None,
watermark: bool = False,
) -> TextGenerationResponse:
...
) -> TextGenerationResponse: ...

@overload
async def text_generation( # type: ignore
Expand All @@ -1278,8 +1276,7 @@ async def text_generation( # type: ignore
truncate: Optional[int] = None,
typical_p: Optional[float] = None,
watermark: bool = False,
) -> AsyncIterable[str]:
...
) -> AsyncIterable[str]: ...

@overload
async def text_generation(
Expand All @@ -1302,8 +1299,7 @@ async def text_generation(
truncate: Optional[int] = None,
typical_p: Optional[float] = None,
watermark: bool = False,
) -> AsyncIterable[TextGenerationStreamResponse]:
...
) -> AsyncIterable[TextGenerationStreamResponse]: ...

async def text_generation(
self,
Expand Down
1 change: 1 addition & 0 deletions src/huggingface_hub/inference/_generated/types/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Contains a base class for all inference types."""

import inspect
import json
import warnings
Expand Down
1 change: 1 addition & 0 deletions src/huggingface_hub/lfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Git LFS related type definitions and utilities"""

import inspect
import io
import os
Expand Down
1 change: 1 addition & 0 deletions src/huggingface_hub/serialization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.
# ruff: noqa: F401
"""Contains helpers to serialize tensors."""

from ._base import StateDictSplit, split_state_dict_into_shards_factory
from ._numpy import split_numpy_state_dict_into_shards
from ._tensorflow import split_tf_state_dict_into_shards
Expand Down
1 change: 1 addition & 0 deletions src/huggingface_hub/serialization/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Contains helpers to split tensors into shards."""

from dataclasses import dataclass, field
from typing import Any, Callable, Dict, List, Optional, TypeVar

Expand Down
1 change: 1 addition & 0 deletions src/huggingface_hub/serialization/_numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Contains numpy-specific helpers."""

from typing import TYPE_CHECKING, Dict

from ._base import FILENAME_PATTERN, MAX_SHARD_SIZE, StateDictSplit, split_state_dict_into_shards_factory
Expand Down
1 change: 1 addition & 0 deletions src/huggingface_hub/serialization/_tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Contains tensorflow-specific helpers."""

import math
import re
from typing import TYPE_CHECKING, Dict
Expand Down
1 change: 1 addition & 0 deletions src/huggingface_hub/serialization/_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Contains pytorch-specific helpers."""

import importlib
from functools import lru_cache
from typing import TYPE_CHECKING, Dict, Tuple
Expand Down
1 change: 1 addition & 0 deletions src/huggingface_hub/utils/_cache_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Contains utilities to manage the HF cache directory."""

import os
import shutil
import time
Expand Down
1 change: 1 addition & 0 deletions src/huggingface_hub/utils/_chunk_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Contains a utility to iterate by chunks over an iterator."""

import itertools
from typing import Iterable, TypeVar

Expand Down
1 change: 1 addition & 0 deletions src/huggingface_hub/utils/_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Contains utilities to handle datetimes in Huggingface Hub."""

from datetime import datetime, timezone


Expand Down
1 change: 1 addition & 0 deletions src/huggingface_hub/utils/_experimental.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Contains utilities to flag a feature as "experimental" in Huggingface Hub."""

import warnings
from functools import wraps
from typing import Callable
Expand Down
1 change: 1 addition & 0 deletions src/huggingface_hub/utils/_git_credential.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Contains utilities to manage Git credentials."""

import re
import subprocess
from typing import List, Optional
Expand Down
1 change: 1 addition & 0 deletions src/huggingface_hub/utils/_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Contains utilities to handle headers to send in calls to Huggingface Hub."""

from typing import Dict, Optional, Union

from .. import constants
Expand Down
1 change: 1 addition & 0 deletions src/huggingface_hub/utils/_hf_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Contain helper class to retrieve/store token from/to local cache."""

import warnings
from pathlib import Path
from typing import Optional
Expand Down
Loading

0 comments on commit 485d313

Please sign in to comment.