Skip to content

Commit a0d6c63

Browse files
committed
[Fix] Fix pre-commit-hook for python3.12
1 parent c46684c commit a0d6c63

23 files changed

+66
-50
lines changed

.github/workflows/lint.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ jobs:
1111
runs-on: ubuntu-22.04
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
2121
pre-commit install
2222
- name: Linting
2323
run: pre-commit run --all-files
2424
- name: Format c/cuda codes with clang-format
25-
uses: DoozyX/clang-format-lint-action@v0.11
25+
uses: DoozyX/clang-format-lint-action@v0.13
2626
with:
2727
source: mmcv/ops/csrc
2828
extensions: h,c,cpp,hpp,cu,cuh

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

+10-5
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
@@ -53,15 +57,16 @@ repos:
5357
hooks:
5458
- id: check-copyright
5559
args: ["mmcv", "tests", "--excludes", "mmcv/ops"]
56-
- repo: https://gitee.com/openmmlab/mirrors-mypy
57-
rev: v0.812
60+
- repo: https://github.com/pre-commit/mirrors-mypy
61+
rev: v1.2.0
5862
hooks:
5963
- id: mypy
6064
exclude: |-
6165
(?x)(
6266
^test
6367
| ^docs
6468
)
69+
additional_dependencies: ["types-setuptools", "types-requests"]
6570
# - repo: local
6671
# hooks:
6772
# - id: clang-format

.pre-commit-config.yaml

+9-4
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
@@ -39,7 +43,7 @@ repos:
3943
- mdformat_frontmatter
4044
- linkify-it-py
4145
- repo: https://github.com/myint/docformatter
42-
rev: v1.3.1
46+
rev: 06907d0
4347
hooks:
4448
- id: docformatter
4549
args: ["--in-place", "--wrap-descriptions", "79"]
@@ -54,14 +58,15 @@ repos:
5458
- id: check-copyright
5559
args: ["mmcv", "tests", "--excludes", "mmcv/ops"]
5660
- repo: https://github.com/pre-commit/mirrors-mypy
57-
rev: v0.812
61+
rev: v1.2.0
5862
hooks:
5963
- id: mypy
6064
exclude: |-
6165
(?x)(
6266
^test
6367
| ^docs
6468
)
69+
additional_dependencies: ["types-setuptools", "types-requests"]
6570
# - repo: local
6671
# hooks:
6772
# - id: clang-format

mmcv/cnn/bricks/drop.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ def drop_path(x: torch.Tensor,
1313
residual blocks).
1414
1515
We follow the implementation
16-
https://github.com/rwightman/pytorch-image-models/blob/a2727c1bf78ba0d7b5727f5f95e37fb7f8866b1f/timm/models/layers/drop.py # noqa: E501
16+
https://github.com/rwightman/pytorch-image-models/blob/a2727c1bf78ba0d7b5727f5f95e37fb7f8866b1f/timm/models/layers/drop.py
17+
# noqa: E501
1718
"""
1819
if drop_prob == 0. or not training:
1920
return x

mmcv/cnn/rfsearch/search.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def __init__(self,
7171
self.by_epoch = by_epoch
7272

7373
def init_model(self, model: nn.Module):
74-
"""init model with search ability.
74+
"""Init model with search ability.
7575
7676
Args:
7777
model (nn.Module): pytorch model
@@ -132,7 +132,7 @@ def step(self, model: nn.Module, work_dir: str) -> None:
132132
)
133133

134134
def estimate_and_expand(self, model: nn.Module) -> None:
135-
"""estimate and search for RFConvOp.
135+
"""Estimate and search for RFConvOp.
136136
137137
Args:
138138
model (nn.Module): pytorch model
@@ -146,7 +146,7 @@ def wrap_model(self,
146146
model: nn.Module,
147147
search_op: str = 'Conv2d',
148148
prefix: str = '') -> None:
149-
"""wrap model to support searchable conv op.
149+
"""Wrap model to support searchable conv op.
150150
151151
Args:
152152
model (nn.Module): pytorch model
@@ -187,7 +187,7 @@ def set_model(self,
187187
search_op: str = 'Conv2d',
188188
init_rates: Optional[int] = None,
189189
prefix: str = '') -> None:
190-
"""set model based on config.
190+
"""Set model based on config.
191191
192192
Args:
193193
model (nn.Module): pytorch model

mmcv/cnn/rfsearch/utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
def write_to_json(config: dict, filename: str):
7-
"""save config to json file.
7+
"""Save config to json file.
88
99
Args:
1010
config (dict): Config to be saved.
@@ -16,7 +16,7 @@ def write_to_json(config: dict, filename: str):
1616

1717

1818
def expand_rates(dilation: tuple, config: dict) -> list:
19-
"""expand dilation rate according to config.
19+
"""Expand dilation rate according to config.
2020
2121
Args:
2222
dilation (int): _description_

mmcv/ops/active_rotated_filter.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ class ActiveRotatedFilterFunction(Function):
1616
"""Encoding the orientation information and generating orientation-
1717
sensitive features.
1818
19-
The details are described in the paper `Align Deep Features for Oriented
20-
Object Detection <https://arxiv.org/abs/2008.09397>_`.
21-
"""
19+
The details are described in the paper
20+
`Align Deep Features for Oriented Object Detection <https://arxiv.org/abs/2008.09397>_`.
21+
""" # noqa: E501
2222

2323
@staticmethod
2424
def forward(ctx, input: torch.Tensor,

mmcv/ops/cc_attention.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def __init__(self, in_channels: int) -> None:
5151
self.in_channels = in_channels
5252

5353
def forward(self, x: torch.Tensor) -> torch.Tensor:
54-
"""forward function of Criss-Cross Attention.
54+
"""Forward function of Criss-Cross Attention.
5555
5656
Args:
5757
x (torch.Tensor): Input feature with the shape of

mmcv/ops/chamfer_distance.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class ChamferDistanceFunction(Function):
1616
"""This is an implementation of the 2D Chamfer Distance.
1717
1818
It has been used in the paper `Oriented RepPoints for Aerial Object
19-
Detection (CVPR 2022) <https://arxiv.org/abs/2105.11111>_`.
19+
Detection (CVPR 2022)
20+
<https://arxiv.org/abs/2105.11111>_`.
2021
"""
2122

2223
@staticmethod

mmcv/ops/correlation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def _output_size(ctx, input1):
116116

117117

118118
class Correlation(nn.Module):
119-
r"""Correlation operator
119+
r"""Correlation operator.
120120
121121
This correlation operator works for optical flow correlation computation.
122122

mmcv/ops/deform_conv.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,9 @@ def _load_from_state_dict(self, state_dict, prefix, local_metadata, strict,
449449

450450
@MODELS.register_module('DCN', force=True)
451451
class DeformConv2dPack_MLU(DeformConv2d):
452-
"""This class is the DCN implementation of the MLU device. The MLU
452+
"""This class is the DCN implementation of the MLU device.
453+
454+
The MLU
453455
backend support of the operator has been implemented in torchvision.
454456
The mmcv registration mechanism is used for multiplexing here. The
455457
torchvision implementation of DCN is called.

mmcv/ops/iou3d.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def boxes_iou3d(boxes_a: Tensor, boxes_b: Tensor) -> Tensor:
4242
Returns:
4343
torch.Tensor: 3D IoU result with shape (M, N).
4444
"""
45-
assert boxes_a.shape[1] == boxes_b.shape[1] == 7,\
45+
assert boxes_a.shape[1] == boxes_b.shape[1] == 7, \
4646
'Input boxes shape should be (N, 7)'
4747

4848
boxes_a_height_max = (boxes_a[:, 2] + boxes_a[:, 5] / 2).view(-1, 1)

mmcv/ops/rotated_feature_align.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ class RotatedFeatureAlignFunction(Function):
1717
correspond to the refined rotate anchors and reconstruct the feature maps
1818
in pixel-wise manner to achieve feature alignment.
1919
20-
The details are described in the paper
21-
`R3Det: Refined Single-Stage Detector with Feature Refinement for Rotating
22-
Object <https://arxiv.org/abs/1908.05612>`_.
20+
The details are described in the paper `R3Det: Refined Single-Stage
21+
Detector with Feature Refinement for Rotating Object
22+
<https://arxiv.org/abs/1908.05612>`_.
2323
"""
2424

2525
@staticmethod

mmcv/ops/scatter_points.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def forward(ctx: Any,
2020
feats: torch.Tensor,
2121
coors: torch.Tensor,
2222
reduce_type: str = 'max') -> Tuple[torch.Tensor, torch.Tensor]:
23-
"""convert kitti points(N, >=3) to voxels.
23+
"""Convert kitti points(N, >=3) to voxels.
2424
2525
Args:
2626
feats (torch.Tensor): [N, C]. Points features to be reduced

mmcv/ops/sparse_modules.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,15 @@ def _mean_update(vals: Union[int, List], m_vals: Union[int, List],
4747

4848

4949
class SparseModule(nn.Module):
50-
"""place holder, All module subclass from this will take sptensor in
50+
"""Place holder, All module subclass from this will take sptensor in
5151
SparseSequential."""
5252
pass
5353

5454

5555
class SparseSequential(SparseModule):
56-
r"""A sequential container.
57-
Modules will be added to it in the order they are passed in the
58-
constructor.
59-
Alternatively, an ordered dict of modules can also be passed in.
56+
r"""A sequential container. Modules will be added to it in the order they
57+
are passed in the constructor. Alternatively, an ordered dict of modules
58+
can also be passed in.
6059
6160
To make it easier to understand, given is a small example::
6261
@@ -189,14 +188,14 @@ def fused(self):
189188

190189

191190
class ToDense(SparseModule):
192-
"""convert SparseConvTensor to NCHW dense tensor."""
191+
"""Convert SparseConvTensor to NCHW dense tensor."""
193192

194193
def forward(self, x: SparseConvTensor):
195194
return x.dense()
196195

197196

198197
class RemoveGrid(SparseModule):
199-
"""remove pre-allocated grid buffer."""
198+
"""Remove pre-allocated grid buffer."""
200199

201200
def forward(self, x: SparseConvTensor):
202201
x.grid = None

mmcv/ops/sparse_structure.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
def scatter_nd(indices: torch.Tensor, updates: torch.Tensor,
88
shape: torch.Tensor) -> torch.Tensor:
9-
"""pytorch edition of tensorflow scatter_nd.
9+
"""Pytorch edition of tensorflow scatter_nd.
1010
1111
this function don't contain except handle code. so use this carefully when
1212
indice repeats, don't support repeat add which is supported in tensorflow.

mmcv/ops/tin_shift.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@ class TINShift(nn.Module):
5555
Temporal Interlace shift is a differentiable temporal-wise frame shifting
5656
which is proposed in "Temporal Interlacing Network"
5757
58-
Please refer to `Temporal Interlacing Network
59-
<https://arxiv.org/abs/2001.06499>`_ for more details.
58+
Please refer to
59+
`Temporal Interlacing Network <https://arxiv.org/abs/2001.06499>`_
60+
for more details.
6061
61-
Code is modified from https://github.com/mit-han-lab/temporal-shift-module
62+
Code is modified from
63+
https://github.com/mit-han-lab/temporal-shift-module
6264
"""
6365

6466
def forward(self, input, shift):

mmcv/ops/upfirdn2d.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020

2121
def _parse_scaling(scaling):
22-
"""parse scaling into list [x, y]"""
22+
"""Parse scaling into list [x, y]"""
2323
if isinstance(scaling, int):
2424
scaling = [scaling, scaling]
2525
assert isinstance(scaling, (list, tuple))
@@ -30,7 +30,7 @@ def _parse_scaling(scaling):
3030

3131

3232
def _parse_padding(padding):
33-
"""parse padding into list [padx0, padx1, pady0, pady1]"""
33+
"""Parse padding into list [padx0, padx1, pady0, pady1]"""
3434
if isinstance(padding, int):
3535
padding = [padding, padding]
3636
assert isinstance(padding, (list, tuple))
@@ -43,7 +43,7 @@ def _parse_padding(padding):
4343

4444

4545
def _get_filter_size(filter):
46-
"""get width and height of filter kernel."""
46+
"""Get width and height of filter kernel."""
4747
if filter is None:
4848
return 1, 1
4949
assert isinstance(filter, torch.Tensor) and filter.ndim in [1, 2]

mmcv/transforms/formatting.py

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def __init__(self, keys: dict) -> None:
110110
def transform(self, results: dict) -> dict:
111111
"""Transform function to convert image in results to
112112
:obj:`torch.Tensor` and transpose the channel order.
113+
113114
Args:
114115
results (dict): Result dict contains the image data to convert.
115116
Returns:

mmcv/transforms/processing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1457,7 +1457,7 @@ class RandomResize(BaseTransform):
14571457
def __init__(
14581458
self,
14591459
scale: Union[Tuple[int, int], Sequence[Tuple[int, int]]],
1460-
ratio_range: Tuple[float, float] = None,
1460+
ratio_range: Optional[Tuple[float, float]] = None,
14611461
resize_type: str = 'Resize',
14621462
**resize_kwargs,
14631463
) -> None:

mmcv/transforms/wrappers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class KeyMapper(BaseTransform):
177177
"""
178178

179179
def __init__(self,
180-
transforms: Union[Transform, List[Transform]] = None,
180+
transforms: Union[Transform, List[Transform], None] = None,
181181
mapping: Optional[Dict] = None,
182182
remapping: Optional[Dict] = None,
183183
auto_remap: Optional[bool] = None,

mmcv/video/optflow.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ def dequantize_flow(dx: np.ndarray,
149149
dx, dy = (dequantize(d, -max_val, max_val, 255) for d in [dx, dy])
150150

151151
if denorm:
152-
dx *= dx.shape[1]
153-
dy *= dx.shape[0]
152+
dx *= dx.shape[1] # type: ignore
153+
dy *= dx.shape[0] # type: ignore
154154
flow = np.dstack((dx, dy))
155155
return flow
156156

mmcv/visualization/image.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def imshow_bboxes(img: Union[str, np.ndarray],
9191
def imshow_det_bboxes(img: Union[str, np.ndarray],
9292
bboxes: np.ndarray,
9393
labels: np.ndarray,
94-
class_names: List[str] = None,
94+
class_names: Optional[List[str]] = None,
9595
score_thr: float = 0,
9696
bbox_color: ColorType = 'green',
9797
text_color: ColorType = 'green',

0 commit comments

Comments
 (0)