Skip to content

Commit 1b59c75

Browse files
Re-enable import sorting disabled by flake8:noqa directive when using ruff linter (#6946)
* Replace wrong ruff:noqa directive with per-file-ignores setting * Remove unnecessary noqa F401 * Replace isort:skip with isort:split * Fix import sorting * Replace inline noqa:F401 with per-file
1 parent 43fd659 commit 1b59c75

File tree

9 files changed

+26
-31
lines changed

9 files changed

+26
-31
lines changed

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ select = ["C", "E", "F", "I", "W"]
1313
lines-after-imports = 2
1414
known-first-party = ["datasets"]
1515

16+
[tool.ruff.lint.per-file-ignores]
17+
"__init__.py" = ["F401", "F403", "F405"]
18+
1619
[tool.pytest.ini_options]
1720
# Test fails if a FutureWarning is thrown by `huggingface_hub`
1821
# Temporarily disabled because transformers 4.41.1 calls deprecated code from `huggingface_hub` that causes FutureWarning

src/datasets/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# ruff: noqa
21
# Copyright 2020 The HuggingFace Datasets Authors and the TensorFlow Datasets Authors.
32
#
43
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -54,10 +53,13 @@
5453
from .utils import logging
5554

5655

57-
# deprecated modules
58-
from datasets import arrow_dataset as _arrow_dataset # isort:skip
59-
from datasets import utils as _utils # isort:skip
60-
from datasets.utils import download_manager as _deprecated_download_manager # isort:skip
56+
# isort: split
57+
58+
# Deprecated modules
59+
from . import arrow_dataset as _arrow_dataset
60+
from . import utils as _utils
61+
from .utils import download_manager as _deprecated_download_manager
62+
6163

6264
_arrow_dataset.concatenate_datasets = concatenate_datasets
6365
_utils.DownloadConfig = DownloadConfig

src/datasets/features/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# ruff: noqa
2-
31
__all__ = [
42
"Audio",
53
"Array2D",

src/datasets/filesystems/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
_has_s3fs = importlib.util.find_spec("s3fs") is not None
1515

1616
if _has_s3fs:
17-
from .s3filesystem import S3FileSystem # noqa: F401
17+
from .s3filesystem import S3FileSystem
1818

1919
COMPRESSION_FILESYSTEMS: List[compression.BaseCompressedFileFileSystem] = [
2020
compression.Bz2FileSystem,

src/datasets/formatting/__init__.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
# ruff: noqa
16-
1715
from typing import Dict, List, Optional, Type
1816

1917
from .. import config
@@ -134,6 +132,4 @@ def get_formatter(format_type: Optional[str], **format_kwargs) -> Formatter:
134132
if format_type in _FORMAT_TYPES_ALIASES_UNAVAILABLE:
135133
raise _FORMAT_TYPES_ALIASES_UNAVAILABLE[format_type]
136134
else:
137-
raise ValueError(
138-
f"Return type should be None or selected in {list(type for type in _FORMAT_TYPES.keys() if type != None)}, but got '{format_type}'"
139-
)
135+
raise ValueError(f"Format type should be one of {list(_FORMAT_TYPES.keys())}, but got '{format_type}'")

src/datasets/packaged_modules/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
from .arrow import arrow
88
from .audiofolder import audiofolder
9-
from .cache import cache # noqa F401
9+
from .cache import cache
1010
from .csv import csv
1111
from .imagefolder import imagefolder
1212
from .json import json
1313
from .pandas import pandas
1414
from .parquet import parquet
15-
from .sql import sql # noqa F401
15+
from .sql import sql
1616
from .text import text
1717
from .webdataset import webdataset
1818

src/datasets/parallel/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .parallel import parallel_backend, parallel_map, ParallelBackendConfig # noqa F401
1+
from .parallel import ParallelBackendConfig, parallel_backend, parallel_map

src/datasets/utils/__init__.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
# ruff: noqa
16-
1715
from . import tqdm as _tqdm # _tqdm is the module
16+
from .experimental import experimental
1817
from .info_utils import VerificationMode
1918
from .logging import disable_progress_bar, enable_progress_bar, is_progress_bar_enabled
20-
from .version import Version
21-
from .experimental import experimental
2219
from .tqdm import (
20+
are_progress_bars_disabled,
2321
disable_progress_bars,
2422
enable_progress_bars,
25-
are_progress_bars_disabled,
2623
tqdm,
2724
)
25+
from .version import Version

tests/_test_patching.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
# isort: skip_file
2-
1+
# ruff: noqa: F401
32
# This is the module that test_patching.py uses to test patch_submodule()
4-
5-
import os # noqa: F401 - this is just for tests
6-
import os as renamed_os # noqa: F401 - this is just for tests
7-
from os import path # noqa: F401 - this is just for tests
8-
from os import path as renamed_path # noqa: F401 - this is just for tests
9-
from os.path import join # noqa: F401 - this is just for tests
10-
from os.path import join as renamed_join # noqa: F401 - this is just for tests
3+
import os
4+
import os as renamed_os
5+
from os import path
6+
from os import path as renamed_path
7+
from os.path import join
8+
from os.path import join as renamed_join
119

1210

13-
open = open # noqa we just need to have a builtin inside this module to test it properly
11+
open = open # we just need to have a builtin inside this module to test it properly

0 commit comments

Comments
 (0)