Skip to content

Commit 6571eb7

Browse files
committed
chore(ci): Update pre-commit
1 parent 10ba061 commit 6571eb7

File tree

18 files changed

+56
-46
lines changed

18 files changed

+56
-46
lines changed

.pre-commit-config.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,30 @@ repos:
1414
- id: check-toml
1515
- id: check-added-large-files
1616
- repo: https://github.com/astral-sh/ruff-pre-commit
17-
rev: v0.9.0
17+
rev: v0.12.3
1818
hooks:
1919
- id: ruff
2020
types_or: [python, pyi, jupyter]
2121
args: [--fix]
2222
- id: ruff-format
2323
types_or: [python, pyi, jupyter]
2424
- repo: https://github.com/pre-commit/mirrors-mypy
25-
rev: "v1.14.1"
25+
rev: "v1.17.0"
2626
hooks:
2727
- id: mypy
2828
additional_dependencies: ['numpy >= 1.22', "ml-dtypes >= 0.1", "pytest", "torch", "jsonpickle"]
2929
args: [--show-error-codes]
3030
- repo: https://github.com/pre-commit/mirrors-clang-format
31-
rev: "v19.1.6"
31+
rev: "v20.1.8"
3232
hooks:
3333
- id: clang-format
3434
- repo: https://github.com/MarcoGorelli/cython-lint
35-
rev: v0.16.6
35+
rev: v0.16.7
3636
hooks:
3737
- id: cython-lint
3838
- id: double-quote-cython-strings
3939
- repo: https://github.com/scop/pre-commit-shfmt
40-
rev: v3.10.0-2
40+
rev: v3.12.0-2
4141
hooks:
4242
- id: shfmt
4343
- repo: https://github.com/shellcheck-py/shellcheck-py
@@ -50,7 +50,7 @@ repos:
5050
# - id: cmake-format
5151
# - id: cmake-lint
5252
- repo: https://github.com/compilerla/conventional-pre-commit
53-
rev: v4.0.0
53+
rev: v4.2.0
5454
hooks:
5555
- id: conventional-pre-commit
5656
stages: [commit-msg]

pyproject.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ line-length = 100
7777
indent-width = 4
7878
target-version = "py39"
7979
include = ["pyproject.toml", "python/**/*.py", "tests/python/**/*.py"]
80-
select = [
80+
lint.select = [
8181
"UP", # pyupgrade, https://docs.astral.sh/ruff/rules/#pyupgrade-up
8282
"PL", # pylint, https://docs.astral.sh/ruff/rules/#pylint-pl
8383
"I", # isort, https://docs.astral.sh/ruff/rules/#isort-i
@@ -88,12 +88,12 @@ select = [
8888
"PTH", # flake8-use-pathlib, https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth
8989
# "D", # pydocstyle, https://docs.astral.sh/ruff/rules/#pydocstyle-d
9090
]
91-
ignore = [
91+
lint.ignore = [
9292
"PLR2004", # pylint: magic-value-comparison
9393
"ANN401", # flake8-annotations: any-type
9494
]
95-
fixable = ["ALL"]
96-
unfixable = []
95+
lint.fixable = ["ALL"]
96+
lint.unfixable = []
9797

9898
[tool.ruff.lint.per-file-ignores]
9999
"__init__.py" = ["F401"]

python/mlc/_cython/base.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class TypeMethod:
183183
kind: int # 0: member method, 1: static method
184184

185185
def as_callable(self) -> Callable[..., typing.Any]:
186-
from .core import func_call # type: ignore[import-not-found]
186+
from .core import func_call # type: ignore[import-not-found] # noqa: PLC0415
187187

188188
func = self.func
189189
if self.kind == 0: # member method
@@ -219,14 +219,16 @@ class TypeInfo:
219219
d_fields: tuple[Field, ...] = ()
220220

221221
def get_parent(self) -> TypeInfo:
222-
from .core import type_index2cached_py_type_info # type: ignore[import-not-found]
222+
from .core import ( # type: ignore[import-not-found] # noqa: PLC0415
223+
type_index2cached_py_type_info,
224+
)
223225

224226
type_index = self.type_ancestors[-1]
225227
return type_index2cached_py_type_info(type_index)
226228

227229

228230
def translate_exception_to_c(exception: Exception) -> tuple[bytes, int, bytes]:
229-
from .core import str_py2c # type: ignore[import-not-found]
231+
from .core import str_py2c # type: ignore[import-not-found] # noqa: PLC0415
230232

231233
def _kind() -> bytes:
232234
kind: str = exception.__class__.__name__
@@ -256,7 +258,7 @@ def _bytes_info() -> bytes:
256258

257259

258260
def translate_exception_from_c(err: Error) -> Exception:
259-
from .core import error_pycode_fake # type: ignore[import-not-found]
261+
from .core import error_pycode_fake # type: ignore[import-not-found] # noqa: PLC0415
260262

261263
kind, info = err.kind, err._info
262264
if info:
@@ -306,7 +308,7 @@ def dtype_normalize(dtype: typing.Any) -> str | DataType:
306308
def _torch_dtype_to_str() -> str | None:
307309
if "torch" not in sys.modules:
308310
return None
309-
import torch
311+
import torch # noqa: PLC0415
310312

311313
if not isinstance(dtype, torch.dtype):
312314
return None
@@ -324,7 +326,7 @@ def _numpy_dtype_to_str() -> str | None:
324326
return np_dtype
325327
if (torch_dtype := _torch_dtype_to_str()) is not None:
326328
return torch_dtype
327-
from mlc.core.dtype import DataType
329+
from mlc.core.dtype import DataType # noqa: PLC0415
328330

329331
return dtype if isinstance(dtype, DataType) else str(dtype)
330332

@@ -333,7 +335,7 @@ def device_normalize(device: typing.Any) -> str | Device:
333335
def _torch_device_to_str() -> str | None:
334336
if "torch" not in sys.modules:
335337
return None
336-
import torch
338+
import torch # noqa: PLC0415
337339

338340
if not isinstance(device, torch.device):
339341
return None
@@ -416,7 +418,7 @@ def attach_method(
416418

417419
def c_class_core(type_key: str) -> Callable[[type[ClsType]], type[ClsType]]:
418420
def decorator(super_type_cls: type[ClsType]) -> type[ClsType]:
419-
from .core import ( # type: ignore[import-not-found]
421+
from .core import ( # type: ignore[import-not-found] # noqa: PLC0415
420422
type_index2type_methods,
421423
type_key2py_type_info,
422424
)

python/mlc/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def probe_vcvarsall() -> Path:
3434

3535

3636
def probe_msvc() -> tuple[Path, ...]:
37-
import setuptools # type: ignore[import-not-found,import-untyped]
37+
import setuptools # type: ignore[import-not-found,import-untyped] # noqa: PLC0415
3838

3939
results = []
4040
if (path := shutil.which("cl.exe", mode=os.X_OK)) is not None:
@@ -67,7 +67,7 @@ def probe_compiler() -> tuple[Path, ...]:
6767

6868

6969
def display_build_info() -> None:
70-
from mlc.core import Func
70+
from mlc.core import Func # noqa: PLC0415
7171

7272
info = Func.get("mlc.core.BuildInfo")()
7373
for k in sorted(info.keys()):

python/mlc/core/device.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ def __hash__(self) -> int:
3939
return hash((Device, *self._device_pair))
4040

4141
def torch(self) -> torch.device:
42-
import torch
42+
import torch # noqa: PLC0415
4343

4444
return torch.device(str(self))
4545

4646
@staticmethod
4747
def register(name: str) -> int:
48-
from .func import Func
48+
from .func import Func # noqa: PLC0415
4949

5050
return Func.get("mlc.base.DeviceTypeRegister")(name)

python/mlc/core/dict.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ def __ne__(self, other: Any) -> bool:
159159
def py(self) -> dict[K, V]:
160160
return container_to_py(self)
161161

162+
def __hash__(self) -> int:
163+
# TODO: hash by elements
164+
return hash((type(self), self._mlc_address))
165+
162166

163167
class _DictKeysView(KeysView[K]):
164168
def __init__(self, mapping: Dict[K, V]) -> None:

python/mlc/core/dtype.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def __hash__(self) -> int:
6262
return hash((DataType, *self._dtype_triple))
6363

6464
def torch(self) -> torch.dtype:
65-
import torch
65+
import torch # noqa: PLC0415
6666

6767
if (ret := getattr(torch, str(self), None)) is not None:
6868
if isinstance(ret, torch.dtype):
@@ -74,6 +74,6 @@ def numpy(self) -> np.dtype:
7474

7575
@staticmethod
7676
def register(name: str, bits: int) -> int:
77-
from .func import Func
77+
from .func import Func # noqa: PLC0415
7878

7979
return Func.get("mlc.base.DataTypeRegister")(name, bits)

python/mlc/core/list.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ def __delitem__(self, i: int) -> None:
126126
def py(self) -> list[T]:
127127
return container_to_py(self)
128128

129+
def __hash__(self) -> int:
130+
# TODO: hash by elements
131+
return hash((type(self), self._mlc_address))
132+
129133

130134
def _normalize_index(i: int, length: int) -> int:
131135
if not -length <= i < length:

python/mlc/core/opaque.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ def register(
4949

5050

5151
def _default_serialize(opaques: list[Any]) -> str:
52-
import jsonpickle # type: ignore[import-untyped]
52+
import jsonpickle # type: ignore[import-untyped] # noqa: PLC0415
5353

5454
return jsonpickle.dumps(list(opaques))
5555

5656

5757
def _default_deserialize(json_str: str) -> list[Any]:
58-
import jsonpickle # type: ignore[import-untyped]
58+
import jsonpickle # type: ignore[import-untyped] # noqa: PLC0415
5959

6060
return jsonpickle.loads(json_str)
6161

python/mlc/core/tensor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def numpy(self) -> np.ndarray:
7777
return np.from_dlpack(self)
7878

7979
def torch(self) -> torch.Tensor:
80-
import torch
80+
import torch # noqa: PLC0415
8181

8282
return torch.from_dlpack(self)
8383

0 commit comments

Comments
 (0)