Skip to content

Commit 2543429

Browse files
MGAMZHAOCHENYE
authored andcommitted
Lint using yapf=0.32.0 on python 3.10.19
1 parent c74ff18 commit 2543429

File tree

13 files changed

+46
-54
lines changed

13 files changed

+46
-54
lines changed

mmengine/_strategy/deepspeed.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,10 @@ def __init__(
310310
self.config.setdefault('gradient_accumulation_steps', 1)
311311
self.config['steps_per_print'] = steps_per_print
312312
self._inputs_to_half = inputs_to_half
313-
assert (exclude_frozen_parameters is None or digit_version(
314-
deepspeed.__version__) >= digit_version('0.13.2')), (
315-
'DeepSpeed >= 0.13.2 is required to enable '
316-
'exclude_frozen_parameters')
313+
assert (exclude_frozen_parameters is None or
314+
digit_version(deepspeed.__version__) >= digit_version('0.13.2')
315+
), ('DeepSpeed >= 0.13.2 is required to enable '
316+
'exclude_frozen_parameters')
317317
self.exclude_frozen_parameters = exclude_frozen_parameters
318318

319319
register_deepspeed_optimizers()

mmengine/config/config.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,9 @@
4646
def _lazy2string(cfg_dict, dict_type=None):
4747
if isinstance(cfg_dict, dict):
4848
dict_type = dict_type or type(cfg_dict)
49-
return dict_type({
50-
k: _lazy2string(v, dict_type)
51-
for k, v in dict.items(cfg_dict)
52-
})
49+
return dict_type(
50+
{k: _lazy2string(v, dict_type)
51+
for k, v in dict.items(cfg_dict)})
5352
elif isinstance(cfg_dict, (tuple, list)):
5453
return type(cfg_dict)(_lazy2string(v, dict_type) for v in cfg_dict)
5554
elif isinstance(cfg_dict, (LazyAttr, LazyObject)):
@@ -272,15 +271,13 @@ def __reduce_ex__(self, proto):
272271
# called by CPython interpreter during pickling. See more details in
273272
# https://github.com/python/cpython/blob/8d61a71f9c81619e34d4a30b625922ebc83c561b/Objects/typeobject.c#L6196 # noqa: E501
274273
if digit_version(platform.python_version()) < digit_version('3.8'):
275-
return (self.__class__, ({
276-
k: v
277-
for k, v in super().items()
278-
}, ), None, None, None)
274+
return (self.__class__, ({k: v
275+
for k, v in super().items()}, ), None,
276+
None, None)
279277
else:
280-
return (self.__class__, ({
281-
k: v
282-
for k, v in super().items()
283-
}, ), None, None, None, None)
278+
return (self.__class__, ({k: v
279+
for k, v in super().items()}, ), None,
280+
None, None, None)
284281

285282
def __eq__(self, other):
286283
if isinstance(other, ConfigDict):

mmengine/dataset/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ def default_collate(data_batch: Sequence) -> Any:
158158
return [default_collate(samples) for samples in transposed]
159159
elif isinstance(data_item, Mapping):
160160
return data_item_type({
161-
key:
162-
default_collate([d[key] for d in data_batch])
161+
key: default_collate([d[key] for d in data_batch])
163162
for key in data_item
164163
})
165164
else:

mmengine/fileio/backends/local_backend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ def isfile(self, filepath: Union[str, Path]) -> bool:
156156
"""
157157
return osp.isfile(filepath)
158158

159-
def join_path(self, filepath: Union[str, Path], *filepaths:
160-
Union[str, Path]) -> str:
159+
def join_path(self, filepath: Union[str, Path],
160+
*filepaths: Union[str, Path]) -> str:
161161
r"""Concatenate all file paths.
162162
163163
Join one or more filepath components intelligently. The return value

mmengine/fileio/file_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,8 @@ def isfile(self, filepath: Union[str, Path]) -> bool:
385385
"""
386386
return self.client.isfile(filepath)
387387

388-
def join_path(self, filepath: Union[str, Path], *filepaths:
389-
Union[str, Path]) -> str:
388+
def join_path(self, filepath: Union[str, Path],
389+
*filepaths: Union[str, Path]) -> str:
390390
r"""Concatenate all file paths.
391391
392392
Join one or more filepath components intelligently. The return value

mmengine/hooks/checkpoint_hook.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,10 @@ def __init__(self,
196196
self.save_best = save_best
197197

198198
# rule logic
199-
assert (isinstance(rule, str) or is_list_of(rule, str) or
200-
(rule
201-
is None)), ('"rule" should be a str or list of str or None, '
202-
f'but got {type(rule)}')
199+
assert (isinstance(rule, str) or is_list_of(rule, str)
200+
or (rule is None)), (
201+
'"rule" should be a str or list of str or None, '
202+
f'but got {type(rule)}')
203203
if isinstance(rule, list):
204204
# check the length of rule list
205205
assert len(rule) in [

mmengine/model/test_time_aug.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,9 @@ def test_step(self, data):
124124
data_list: Union[List[dict], List[list]]
125125
if isinstance(data, dict):
126126
num_augs = len(data[next(iter(data))])
127-
data_list = [{
128-
key: value[idx]
129-
for key, value in data.items()
130-
} for idx in range(num_augs)]
127+
data_list = [{key: value[idx]
128+
for key, value in data.items()}
129+
for idx in range(num_augs)]
131130
elif isinstance(data, (tuple, list)):
132131
num_augs = len(data[0])
133132
data_list = [[_data[idx] for _data in data]

mmengine/runner/checkpoint.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -601,10 +601,9 @@ def _load_checkpoint_to_model(model,
601601
# strip prefix of state_dict
602602
metadata = getattr(state_dict, '_metadata', OrderedDict())
603603
for p, r in revise_keys:
604-
state_dict = OrderedDict({
605-
re.sub(p, r, k): v
606-
for k, v in state_dict.items()
607-
})
604+
state_dict = OrderedDict(
605+
{re.sub(p, r, k): v
606+
for k, v in state_dict.items()})
608607
# Keep metadata in state_dict
609608
state_dict._metadata = metadata
610609

mmengine/utils/dl_utils/torch_ops.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
from ..version_utils import digit_version
55
from .parrots_wrapper import TORCH_VERSION
66

7-
_torch_version_meshgrid_indexing = ('parrots' not in TORCH_VERSION
8-
and digit_version(TORCH_VERSION)
9-
>= digit_version('1.10.0a0'))
7+
_torch_version_meshgrid_indexing = (
8+
'parrots' not in TORCH_VERSION
9+
and digit_version(TORCH_VERSION) >= digit_version('1.10.0a0'))
1010

1111

1212
def torch_meshgrid(*tensors):

mmengine/visualization/visualizer.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -754,9 +754,8 @@ def draw_bboxes(
754754
assert bboxes.shape[-1] == 4, (
755755
f'The shape of `bboxes` should be (N, 4), but got {bboxes.shape}')
756756

757-
assert (bboxes[:, 0] <= bboxes[:, 2]).all() and (bboxes[:, 1]
758-
<= bboxes[:,
759-
3]).all()
757+
assert (bboxes[:, 0] <= bboxes[:, 2]).all() and (bboxes[:, 1] <=
758+
bboxes[:, 3]).all()
760759
if not self._is_posion_valid(bboxes.reshape((-1, 2, 2))):
761760
warnings.warn(
762761
'Warning: The bbox is out of bounds,'

0 commit comments

Comments
 (0)