Skip to content

Commit fe04348

Browse files
committed
Saner linters
1 parent d58d137 commit fe04348

File tree

15 files changed

+190
-478
lines changed

15 files changed

+190
-478
lines changed

.github/workflows/ci.yml

+2-5
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,8 @@ jobs:
3535
pixi-version: v0.39.0
3636
cache: true
3737
environments: lint
38-
- name: Run Pylint, Mypy & Pyright
39-
run: |
40-
pixi run -e lint pylint
41-
pixi run -e lint mypy
42-
pixi run -e lint pyright
38+
- name: Run Mypy
39+
run: pixi run -e lint mypy
4340

4441
checks:
4542
name: Check ${{ matrix.environment }}

.pre-commit-config.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ repos:
1212
additional_dependencies: [black==24.*]
1313

1414
- repo: https://github.com/pre-commit/pre-commit-hooks
15-
rev: "v4.6.0"
15+
rev: "v5.0.0"
1616
hooks:
1717
- id: check-added-large-files
1818
- id: check-case-conflict
@@ -35,14 +35,14 @@ repos:
3535
- id: rst-inline-touching-normal
3636

3737
- repo: https://github.com/rbubley/mirrors-prettier
38-
rev: "v3.3.3"
38+
rev: "v3.4.2"
3939
hooks:
4040
- id: prettier
4141
types_or: [yaml, markdown, html, css, scss, javascript, json]
4242
args: [--prose-wrap=always]
4343

4444
- repo: https://github.com/astral-sh/ruff-pre-commit
45-
rev: "v0.6.1"
45+
rev: "v0.8.2"
4646
hooks:
4747
- id: ruff
4848
args: ["--fix", "--show-fixes"]
@@ -68,13 +68,13 @@ repos:
6868
exclude: .pre-commit-config.yaml
6969

7070
- repo: https://github.com/abravalheri/validate-pyproject
71-
rev: "v0.19"
71+
rev: "v0.23"
7272
hooks:
7373
- id: validate-pyproject
7474
additional_dependencies: ["validate-pyproject-schema-store[all]"]
7575

7676
- repo: https://github.com/python-jsonschema/check-jsonschema
77-
rev: "0.29.1"
77+
rev: "0.30.0"
7878
hooks:
7979
- id: check-dependabot
8080
- id: check-github-workflows

docs/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 16 16">
3939
<path fill-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path>
4040
</svg>
41-
""",
41+
""", # noqa: E501
4242
"class": "",
4343
},
4444
],

docs/contributing.md

-2
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,7 @@ pixi run ipython
7777

7878
```
7979
pixi run pre-commit
80-
pixi run pylint
8180
pixi run mypy
82-
pixi run pyright
8381
```
8482

8583
Alternative environments are available with a subset of the dependencies and

pixi.lock

+134-369
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+25-46
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,7 @@ array-api-extra = { path = ".", editable = true }
7070

7171
[tool.pixi.feature.lint.dependencies]
7272
pre-commit = "*"
73-
pylint = "*"
74-
basedmypy = "*"
75-
basedpyright = "*"
73+
mypy = "*"
7674
typing_extensions = ">=4.12.2,<4.13"
7775
# import dependencies for mypy:
7876
array-api-strict = "*"
@@ -81,11 +79,9 @@ pytest = "*"
8179

8280
[tool.pixi.feature.lint.tasks]
8381
pre-commit-install = { cmd = "pre-commit install" }
84-
pre-commit = { cmd = "pre-commit run -v --all-files --show-diff-on-failure" }
82+
pre-commit = { cmd = "pre-commit run --all-files" }
8583
mypy = { cmd = "mypy", cwd = "." }
86-
pylint = { cmd = ["pylint", "array_api_extra"], cwd = "src" }
87-
pyright = { cmd = "basedpyright", cwd = "." }
88-
lint = { depends-on = ["pre-commit", "pylint", "mypy", "pyright"] }
84+
lint = { depends-on = ["pre-commit", "mypy"] }
8985

9086
[tool.pixi.feature.tests.dependencies]
9187
pytest = ">=6"
@@ -154,42 +150,34 @@ run.source = ["array_api_extra"]
154150
report.exclude_also = [
155151
'\.\.\.',
156152
'if typing.TYPE_CHECKING:',
153+
'if TYPE_CHECKING:',
157154
]
158155

159156

160157
# mypy
161158

162159
[tool.mypy]
163-
files = ["src", "tests"]
160+
files = ["src", "tests", "vendor_tests"]
164161
python_version = "3.10"
165-
warn_unused_configs = true
166162
strict = true
167-
enable_error_code = ["ignore-without-code", "redundant-expr", "truthy-bool"]
168-
warn_unreachable = true
169-
disallow_untyped_defs = false
170-
disallow_incomplete_defs = false
171163
# data-apis/array-api#589
172164
disallow_any_expr = false
165+
disallow_incomplete_defs = false
166+
disallow_untyped_defs = false
167+
disallow_untyped_decorators = true
168+
ignore_missing_imports = true
169+
no_implicit_optional = true
170+
show_error_codes = true
171+
warn_redundant_casts = true
172+
warn_unused_configs = true
173+
warn_unused_ignores = true
174+
warn_unreachable = true
175+
173176

174177
[[tool.mypy.overrides]]
175178
module = "array_api_extra.*"
176-
disallow_untyped_defs = true
177179
disallow_incomplete_defs = true
178-
179-
180-
# pyright
181-
182-
[tool.basedpyright]
183-
include = ["src", "tests"]
184-
pythonVersion = "3.10"
185-
pythonPlatform = "All"
186-
typeCheckingMode = "all"
187-
188-
# data-apis/array-api#589
189-
reportAny = false
190-
reportExplicitAny = false
191-
# data-apis/array-api-strict#6
192-
reportUnknownMemberType = false
180+
disallow_untyped_defs = true
193181

194182

195183
# Ruff
@@ -200,11 +188,16 @@ target-version = "py310"
200188
[tool.ruff.lint]
201189
extend-select = [
202190
"B", # flake8-bugbear
191+
"F", # Pyflakes
203192
"I", # isort
193+
"E", # Pycodestyle
194+
"W", # Pycodestyle
195+
"N", # pep8-naming
204196
"ARG", # flake8-unused-arguments
205197
"C4", # flake8-comprehensions
206198
"EM", # flake8-errmsg
207199
"ICN", # flake8-import-conventions
200+
"ISC", # flake8-implicit-str-concat
208201
"G", # flake8-logging-format
209202
"PGH", # pygrep-hooks
210203
"PIE", # flake8-pie
@@ -220,29 +213,15 @@ extend-select = [
220213
"EXE", # flake8-executable
221214
"NPY", # NumPy specific rules
222215
"PD", # pandas-vet
216+
"UP", # Pyupgrade
223217
]
224218
ignore = [
225219
"PLR09", # Too many <...>
226220
"PLR2004", # Magic value used in comparison
227221
"ISC001", # Conflicts with formatter
222+
"N802", # Function name should be lowercase
223+
"N806", # Variable in function should be lowercase
228224
]
229225

230226
[tool.ruff.lint.per-file-ignores]
231227
"tests/**" = ["T20"]
232-
233-
234-
# Pylint
235-
236-
[tool.pylint]
237-
py-version = "3.10"
238-
ignore-paths = [".*/_version.py"]
239-
reports.output-format = "colorized"
240-
similarities.ignore-imports = "yes"
241-
messages_control.disable = [
242-
"design",
243-
"fixme",
244-
"line-too-long",
245-
"missing-module-docstring",
246-
"missing-function-docstring",
247-
"wrong-import-position",
248-
]

src/array_api_extra/__init__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
from __future__ import annotations # https://github.com/pylint-dev/pylint/pull/9990
1+
from __future__ import annotations
22

33
from ._funcs import atleast_nd, cov, create_diagonal, expand_dims, kron, setdiff1d, sinc
44

55
__version__ = "0.3.3.dev0"
66

7-
# pylint: disable=duplicate-code
87
__all__ = [
98
"__version__",
109
"atleast_nd",

src/array_api_extra/_funcs.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
from __future__ import annotations # https://github.com/pylint-dev/pylint/pull/9990
1+
from __future__ import annotations
22

3-
import typing
43
import warnings
54

6-
if typing.TYPE_CHECKING:
7-
from ._lib._typing import Array, ModuleType
8-
95
from ._lib import _utils
106
from ._lib._compat import array_namespace
7+
from ._lib._typing import Array, ModuleType
118

129
__all__ = [
1310
"atleast_nd",

src/array_api_extra/_lib/_compat.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
from __future__ import annotations
44

55
try:
6-
from ..._array_api_compat_vendor import ( # pyright: ignore[reportMissingImports]
7-
array_namespace, # pyright: ignore[reportUnknownVariableType]
8-
device, # pyright: ignore[reportUnknownVariableType]
6+
from ..._array_api_compat_vendor import (
7+
array_namespace,
8+
device,
99
)
1010
except ImportError:
11-
from array_api_compat import ( # pyright: ignore[reportMissingTypeStubs]
12-
array_namespace, # pyright: ignore[reportUnknownVariableType]
11+
from array_api_compat import (
12+
array_namespace,
1313
device,
1414
)
1515

src/array_api_extra/_lib/_typing.py

+5-17
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
1-
from __future__ import annotations # https://github.com/pylint-dev/pylint/pull/9990
1+
from __future__ import annotations
22

3-
import typing
43
from types import ModuleType
54
from typing import Any
65

7-
if typing.TYPE_CHECKING:
8-
from typing_extensions import override
6+
# To be changed to a Protocol later (see data-apis/array-api#589)
7+
Array = Any
8+
Device = Any
99

10-
# To be changed to a Protocol later (see data-apis/array-api#589)
11-
Array = Any # type: ignore[no-any-explicit]
12-
Device = Any # type: ignore[no-any-explicit]
13-
else:
14-
15-
def no_op_decorator(f): # pyright: ignore[reportUnreachable]
16-
return f
17-
18-
override = no_op_decorator
19-
20-
__all__ = ["ModuleType", "override"]
21-
if typing.TYPE_CHECKING:
22-
__all__ += ["Array", "Device"]
10+
__all__ = ["Array", "Device", "ModuleType"]

src/array_api_extra/_lib/_utils.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
from __future__ import annotations # https://github.com/pylint-dev/pylint/pull/9990
2-
3-
import typing
4-
5-
if typing.TYPE_CHECKING:
6-
from ._typing import Array, ModuleType
1+
from __future__ import annotations
72

83
from . import _compat
4+
from ._typing import Array, ModuleType
95

106
__all__ = ["in1d", "mean"]
117

tests/test_funcs.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
from __future__ import annotations # https://github.com/pylint-dev/pylint/pull/9990
1+
from __future__ import annotations
22

33
import contextlib
4-
import typing
54
import warnings
65

76
# data-apis/array-api-strict#6
8-
import array_api_strict as xp # type: ignore[import-untyped] # pyright: ignore[reportMissingTypeStubs]
7+
import array_api_strict as xp
98
import numpy as np
109
import pytest
1110
from numpy.testing import assert_allclose, assert_array_equal, assert_equal
@@ -19,9 +18,7 @@
1918
setdiff1d,
2019
sinc,
2120
)
22-
23-
if typing.TYPE_CHECKING:
24-
from array_api_extra._lib._typing import Array
21+
from array_api_extra._lib._typing import Array
2522

2623

2724
class TestAtLeastND:

tests/test_utils.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
from __future__ import annotations # https://github.com/pylint-dev/pylint/pull/9990
2-
3-
import typing
1+
from __future__ import annotations
42

53
# data-apis/array-api-strict#6
6-
import array_api_strict as xp # type: ignore[import-untyped] # pyright: ignore[reportMissingTypeStubs]
4+
import array_api_strict as xp
75
import pytest
86
from numpy.testing import assert_array_equal
97

8+
from array_api_extra._lib._typing import Array
109
from array_api_extra._lib._utils import in1d
1110

12-
if typing.TYPE_CHECKING:
13-
from array_api_extra._lib._typing import Array
14-
1511

1612
# some test coverage already provided by TestSetDiff1D
1713
class TestIn1D:

tests/test_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from __future__ import annotations # https://github.com/pylint-dev/pylint/pull/9990
1+
from __future__ import annotations
22

33
import importlib.metadata
44

vendor_tests/test_vendor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def test_vendor_compat():
88
from ._array_api_compat_vendor import array_namespace
99

1010
x = xp.asarray([1, 2, 3])
11-
assert array_namespace(x) is xp
11+
assert array_namespace(x) is xp # type: ignore[no-untyped-call]
1212

1313

1414
def test_vendor_extra():

0 commit comments

Comments
 (0)