Skip to content

Commit cc3b74b

Browse files
HAOCHENYEzhouzaida
andauthored
[Fix] Fix lint (#1598)
* [Fix] Fix lint * [Fix] Fix lint * Update mmengine/dist/utils.py Co-authored-by: Zaida Zhou <[email protected]> --------- Co-authored-by: Zaida Zhou <[email protected]>
1 parent c9b5996 commit cc3b74b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+146
-134
lines changed

.github/workflows/lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v2
14-
- name: Set up Python 3.7
14+
- name: Set up Python 3.10.15
1515
uses: actions/setup-python@v2
1616
with:
17-
python-version: 3.7
17+
python-version: '3.10.15'
1818
- name: Install pre-commit hook
1919
run: |
2020
pip install pre-commit

.github/workflows/pr_stage_test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
name: pr_stage_test
22

3+
env:
4+
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
5+
6+
37
on:
48
pull_request:
59
paths-ignore:

.pre-commit-config-zh-cn.yaml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
exclude: ^tests/data/
22
repos:
3-
- repo: https://gitee.com/openmmlab/mirrors-flake8
4-
rev: 5.0.4
3+
- repo: https://github.com/pre-commit/pre-commit
4+
rev: v4.0.0
5+
hooks:
6+
- id: validate_manifest
7+
- repo: https://github.com/PyCQA/flake8
8+
rev: 7.1.1
59
hooks:
610
- id: flake8
711
- repo: https://gitee.com/openmmlab/mirrors-isort
@@ -13,7 +17,7 @@ repos:
1317
hooks:
1418
- id: yapf
1519
- repo: https://gitee.com/openmmlab/mirrors-pre-commit-hooks
16-
rev: v4.3.0
20+
rev: v5.0.0
1721
hooks:
1822
- id: trailing-whitespace
1923
- id: check-yaml
@@ -55,11 +59,12 @@ repos:
5559
args: ["mmengine", "tests"]
5660
- id: remove-improper-eol-in-cn-docs
5761
- repo: https://gitee.com/openmmlab/mirrors-mypy
58-
rev: v0.812
62+
rev: v1.2.0
5963
hooks:
6064
- id: mypy
6165
exclude: |-
6266
(?x)(
6367
^examples
6468
| ^docs
6569
)
70+
additional_dependencies: ["types-setuptools", "types-requests", "types-PyYAML"]

.pre-commit-config.yaml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
exclude: ^tests/data/
22
repos:
3+
- repo: https://github.com/pre-commit/pre-commit
4+
rev: v4.0.0
5+
hooks:
6+
- id: validate_manifest
37
- repo: https://github.com/PyCQA/flake8
4-
rev: 5.0.4
8+
rev: 7.1.1
59
hooks:
610
- id: flake8
711
- repo: https://github.com/PyCQA/isort
@@ -13,7 +17,7 @@ repos:
1317
hooks:
1418
- id: yapf
1519
- repo: https://github.com/pre-commit/pre-commit-hooks
16-
rev: v4.3.0
20+
rev: v5.0.0
1721
hooks:
1822
- id: trailing-whitespace
1923
- id: check-yaml
@@ -34,12 +38,8 @@ repos:
3438
- mdformat-openmmlab
3539
- mdformat_frontmatter
3640
- linkify-it-py
37-
- repo: https://github.com/codespell-project/codespell
38-
rev: v2.2.1
39-
hooks:
40-
- id: codespell
4141
- repo: https://github.com/myint/docformatter
42-
rev: v1.3.1
42+
rev: 06907d0
4343
hooks:
4444
- id: docformatter
4545
args: ["--in-place", "--wrap-descriptions", "79"]
@@ -55,11 +55,12 @@ repos:
5555
args: ["mmengine", "tests"]
5656
- id: remove-improper-eol-in-cn-docs
5757
- repo: https://github.com/pre-commit/mirrors-mypy
58-
rev: v0.812
58+
rev: v1.2.0
5959
hooks:
6060
- id: mypy
6161
exclude: |-
6262
(?x)(
6363
^examples
6464
| ^docs
6565
)
66+
additional_dependencies: ["types-setuptools", "types-requests", "types-PyYAML"]

mmengine/_strategy/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ def build_optim_wrapper(
499499
'"type" and "constructor" are not in '
500500
f'optimizer, but got {name}={optim}')
501501
optim_wrappers[name] = optim
502-
return OptimWrapperDict(**optim_wrappers)
502+
return OptimWrapperDict(**optim_wrappers) # type: ignore
503503
else:
504504
raise TypeError('optimizer wrapper should be an OptimWrapper '
505505
f'object or dict, but got {optim_wrapper}')

mmengine/_strategy/colossalai.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def resume(
361361
map_location: Union[str, Callable] = 'default',
362362
callback: Optional[Callable] = None,
363363
) -> dict:
364-
"""override this method since colossalai resume optimizer from filename
364+
"""Override this method since colossalai resume optimizer from filename
365365
directly."""
366366
self.logger.info(f'Resume checkpoint from {filename}')
367367

mmengine/_strategy/distributed.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def _setup_distributed( # type: ignore
5353
init_dist(launcher, backend, **kwargs)
5454

5555
def convert_model(self, model: nn.Module) -> nn.Module:
56-
"""convert all ``BatchNorm`` layers in the model to ``SyncBatchNorm``
56+
"""Convert all ``BatchNorm`` layers in the model to ``SyncBatchNorm``
5757
(SyncBN) or ``mmcv.ops.sync_bn.SyncBatchNorm`` (MMSyncBN) layers.
5858
5959
Args:

mmengine/config/config.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ class Config:
393393

394394
def __init__(
395395
self,
396-
cfg_dict: dict = None,
396+
cfg_dict: Optional[dict] = None,
397397
cfg_text: Optional[str] = None,
398398
filename: Optional[Union[str, Path]] = None,
399399
env_variables: Optional[dict] = None,
@@ -1227,7 +1227,8 @@ def is_base_line(c):
12271227
if base_code is not None:
12281228
base_code = ast.Expression( # type: ignore
12291229
body=base_code.value) # type: ignore
1230-
base_files = eval(compile(base_code, '', mode='eval'))
1230+
base_files = eval(compile(base_code, '',
1231+
mode='eval')) # type: ignore
12311232
else:
12321233
base_files = []
12331234
elif file_format in ('.yml', '.yaml', '.json'):
@@ -1288,7 +1289,7 @@ def _get_cfg_path(cfg_path: str,
12881289
def _merge_a_into_b(a: dict,
12891290
b: dict,
12901291
allow_list_keys: bool = False) -> dict:
1291-
"""merge dict ``a`` into dict ``b`` (non-inplace).
1292+
"""Merge dict ``a`` into dict ``b`` (non-inplace).
12921293
12931294
Values in ``a`` will overwrite ``b``. ``b`` is copied first to avoid
12941295
in-place modifications.
@@ -1358,22 +1359,22 @@ def auto_argparser(description=None):
13581359

13591360
@property
13601361
def filename(self) -> str:
1361-
"""get file name of config."""
1362+
"""Get file name of config."""
13621363
return self._filename
13631364

13641365
@property
13651366
def text(self) -> str:
1366-
"""get config text."""
1367+
"""Get config text."""
13671368
return self._text
13681369

13691370
@property
13701371
def env_variables(self) -> dict:
1371-
"""get used environment variables."""
1372+
"""Get used environment variables."""
13721373
return self._env_variables
13731374

13741375
@property
13751376
def pretty_text(self) -> str:
1376-
"""get formatted python config text."""
1377+
"""Get formatted python config text."""
13771378

13781379
indent = 4
13791380

@@ -1727,17 +1728,17 @@ def to_dict(self, keep_imported: bool = False):
17271728

17281729

17291730
class DictAction(Action):
1730-
"""
1731-
argparse action to split an argument into KEY=VALUE form
1732-
on the first = and append to a dictionary. List options can
1733-
be passed as comma separated values, i.e 'KEY=V1,V2,V3', or with explicit
1734-
brackets, i.e. 'KEY=[V1,V2,V3]'. It also support nested brackets to build
1735-
list/tuple values. e.g. 'KEY=[(V1,V2),(V3,V4)]'
1731+
"""Argparse action to split an argument into KEY=VALUE form on the first =
1732+
and append to a dictionary.
1733+
1734+
List options can be passed as comma separated values, i.e 'KEY=V1,V2,V3',
1735+
or with explicit brackets, i.e. 'KEY=[V1,V2,V3]'. It also support nested
1736+
brackets to build list/tuple values. e.g. 'KEY=[(V1,V2),(V3,V4)]'
17361737
"""
17371738

17381739
@staticmethod
17391740
def _parse_int_float_bool(val: str) -> Union[int, float, bool, Any]:
1740-
"""parse int/float/bool value in the string."""
1741+
"""Parse int/float/bool value in the string."""
17411742
try:
17421743
return int(val)
17431744
except ValueError:
@@ -1822,7 +1823,7 @@ def __call__(self,
18221823
parser: ArgumentParser,
18231824
namespace: Namespace,
18241825
values: Union[str, Sequence[Any], None],
1825-
option_string: str = None):
1826+
option_string: str = None): # type: ignore
18261827
"""Parse Variables in string and add them into argparser.
18271828
18281829
Args:

mmengine/dist/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ def cast_data_device(
563563
Tensor or list or dict: ``data`` was casted to ``device``.
564564
"""
565565
if out is not None:
566-
if type(data) != type(out):
566+
if type(data) is not type(out):
567567
raise TypeError(
568568
'out should be the same type with data, but got data is '
569569
f'{type(data)} and out is {type(data)}')

mmengine/evaluator/metric.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,11 @@ def __init__(self,
175175
self.out_file_path = out_file_path
176176

177177
def process(self, data_batch: Any, predictions: Sequence[dict]) -> None:
178-
"""transfer tensors in predictions to CPU."""
178+
"""Transfer tensors in predictions to CPU."""
179179
self.results.extend(_to_cpu(predictions))
180180

181181
def compute_metrics(self, results: list) -> dict:
182-
"""dump the prediction results to a pickle file."""
182+
"""Dump the prediction results to a pickle file."""
183183
dump(results, self.out_file_path)
184184
print_log(
185185
f'Results has been saved to {self.out_file_path}.',
@@ -188,7 +188,7 @@ def compute_metrics(self, results: list) -> dict:
188188

189189

190190
def _to_cpu(data: Any) -> Any:
191-
"""transfer all tensors and BaseDataElement to cpu."""
191+
"""Transfer all tensors and BaseDataElement to cpu."""
192192
if isinstance(data, (Tensor, BaseDataElement)):
193193
return data.to('cpu')
194194
elif isinstance(data, list):

0 commit comments

Comments
 (0)