Skip to content

Commit 7f0f493

Browse files
authored
Merge pull request #569 from numpy/tighter-ruff-config
2 parents 0fa4576 + 7eca5cf commit 7f0f493

Some content is hidden

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

55 files changed

+492
-618
lines changed

pyproject.toml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -180,35 +180,26 @@ reportPrivateLocalImportUsage = true
180180
reportUnannotatedClassAttribute = false
181181
strictGenericNarrowing = true
182182

183+
183184
[tool.ruff]
184185
src = ["src", "tool"]
185186
extend-exclude = [".git", ".mypy_cache", ".tox", ".venv"]
186187
force-exclude = true
187-
# https://typing.python.org/en/latest/guides/writing_stubs.html#maximum-line-length
188188
line-length = 120
189189
preview = true
190190

191191
[tool.ruff.format]
192-
docstring-code-format = true
193192
line-ending = "lf"
194193

195194
[tool.ruff.lint]
196195
select = ["ALL"]
197-
ignore = [
198-
"FBT", # flake8-boolean-trap
199-
"CPY", # flake8-copyright
200-
"EM", # flake8-errmsg
201-
"FIX", # flake8-fixme
202-
"ANN401", # flake8-annotations: any-type
203-
"PYI041", # flake8-pyi: redundant-numeric-union
204-
]
196+
ignore = ["CPY", "FIX002"]
205197

206198
[tool.ruff.lint.per-file-ignores]
207199
"*.pyi" = [
208200
"N", # pep8-naming
209201
"TD", # flake8-todo
210202
"COM812", # flake8-commas: missing-trailing-comma
211-
"PYI054", # flake8-pyi: numeric-literal-too-long
212203
"PLC2701", # pylint/C: import-private-name
213204
]
214205

src/_numtype/.ruff.toml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,4 @@ extend = "../../pyproject.toml"
22
line-length = 120
33

44
[lint]
5-
extend-ignore = [
6-
"A", # flake8-builtins
7-
"PYI042", # flake8-pyi: snake-case-type-alias
8-
"PYI064", # flake8-pyi: redundant-final-literal
9-
"SLF001", # flake8-self: private-member-access
10-
"PLR2044", # pylint/R: empty-comment
11-
"PLR6301", # pylint/R: no-self-use
12-
"PLW3201", # pylint/W: bad-dunder-method-name
13-
]
5+
extend-ignore = ["PLR2044"] # pylint/R: empty-comment

src/_numtype/_dtype.pyi

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,22 +93,22 @@ _ToDType2 = TypeAliasType(
9393
type_params=(_ScalarT, _T),
9494
)
9595

96-
_c_i16: TypeAlias = ct.c_int16 | ct.c_short
97-
_c_u16: TypeAlias = ct.c_uint16 | ct.c_ushort
98-
_c_i32: TypeAlias = ct.c_int32 | ct.c_int
99-
_c_u32: TypeAlias = ct.c_uint32 | ct.c_uint
100-
_c_i64: TypeAlias = ct.c_int64 | ct.c_longlong | ct.c_ssize_t
101-
_c_u64: TypeAlias = ct.c_uint64 | ct.c_ulonglong | ct.c_size_t | ct.c_void_p
96+
_C_i16: TypeAlias = ct.c_int16 | ct.c_short
97+
_C_u16: TypeAlias = ct.c_uint16 | ct.c_ushort
98+
_C_i32: TypeAlias = ct.c_int32 | ct.c_int
99+
_C_u32: TypeAlias = ct.c_uint32 | ct.c_uint
100+
_C_i64: TypeAlias = ct.c_int64 | ct.c_longlong | ct.c_ssize_t
101+
_C_u64: TypeAlias = ct.c_uint64 | ct.c_ulonglong | ct.c_size_t | ct.c_void_p
102102

103103
ToDTypeBool: TypeAlias = _ToDType2[np.bool, ct.c_bool | bool] | _BoolCodes
104104
ToDTypeInt8: TypeAlias = _ToDType2[np.int8, ct.c_int8] | _Int8Codes
105105
ToDTypeUInt8: TypeAlias = _ToDType2[np.uint8, ct.c_uint8] | _UInt8Codes
106-
ToDTypeInt16: TypeAlias = _ToDType2[np.int16, _c_i16] | _Int16Codes
107-
ToDTypeUInt16: TypeAlias = _ToDType2[np.uint16, _c_u16] | _UInt16Codes
108-
ToDTypeInt32: TypeAlias = _ToDType2[np.int32, _c_i32] | _Int32Codes
109-
ToDTypeUInt32: TypeAlias = _ToDType2[np.uint32, _c_u32] | _UInt32Codes
110-
ToDTypeInt64: TypeAlias = _ToDType2[np.int64, _c_i64 | JustInt] | _Int64Codes | _IntPCodes
111-
ToDTypeUInt64: TypeAlias = _ToDType2[np.uint64, _c_u64] | _UInt64Codes | _UIntPCodes
106+
ToDTypeInt16: TypeAlias = _ToDType2[np.int16, _C_i16] | _Int16Codes
107+
ToDTypeUInt16: TypeAlias = _ToDType2[np.uint16, _C_u16] | _UInt16Codes
108+
ToDTypeInt32: TypeAlias = _ToDType2[np.int32, _C_i32] | _Int32Codes
109+
ToDTypeUInt32: TypeAlias = _ToDType2[np.uint32, _C_u32] | _UInt32Codes
110+
ToDTypeInt64: TypeAlias = _ToDType2[np.int64, _C_i64 | JustInt] | _Int64Codes | _IntPCodes
111+
ToDTypeUInt64: TypeAlias = _ToDType2[np.uint64, _C_u64] | _UInt64Codes | _UIntPCodes
112112
ToDTypeULong: TypeAlias = np.dtypes.ULongDType | type[ct.c_ulong] | _ULongCodes
113113
ToDTypeLong: TypeAlias = np.dtypes.LongDType | type[ct.c_long] | _LongCodes
114114
ToDTypeFloat16: TypeAlias = _ToDType[np.float16] | _Float16Codes

src/_numtype/_scalar.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ __all__ = [
1919
###
2020
# Sized abstract scalar type aliases.
2121

22+
# ruff: noqa: PYI042
23+
2224
integer8: TypeAlias = np.uint8 | np.int8
2325
integer16: TypeAlias = np.uint16 | np.int16
2426
integer32: TypeAlias = np.uint32 | np.int32

src/_numtype/_scalar_co.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ __all__ = [
3737
# See https://github.com/numpy/numtype/issues/366 for the scalar promotion table and
3838
# https://numpy.org/neps/nep-0050-scalar-promotion.html for the official specification.
3939

40+
# ruff: noqa: PYI042
41+
4042
co_int8: TypeAlias = np.int8 | np.bool
4143
co_int16: TypeAlias = np.int16 | co_integer8
4244
co_int32: TypeAlias = np.int32 | co_integer16

src/numpy-stubs/.ruff.toml

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,7 @@ line-length = 120
44
[lint]
55
extend-ignore = [
66
"A", # flake8-builtins
7-
"S404", # flake8-bandit: suspicious-subprocess-import
8-
"PYI042", # flake8-pyi: snake-case-type-alias # TODO
9-
"PYI047", # flake8-pyi: unused-private-type-alias # TODO
10-
"PYI064", # flake8-pyi: redundant-final-literal
11-
"SLF001", # flake8-self: private-member-access
12-
"E741", # pycodestyle/E: ambiguous-variable-name
13-
"E742", # pycodestyle/E: ambiguous-class-name
14-
"E743", # pycodestyle/E: ambiguous-function-name
15-
"PLR2044", # pylint/R: empty-comment
16-
"PLR6301", # pylint/R: no-self-use
17-
"PLR0904", # pylint/R: too-many-public-methods
18-
"PLR0913", # pylint/R: too-many-arguments
19-
"PLR0917", # pylint/R: too-many-positional-arguments
20-
"PLW3201", # pylint/W: bad-dunder-method-name
7+
"ANN401", # flake8-annotations: any-type
8+
"SLF001", # flake8-self: private-member-access
9+
"PLR2044", # pylint/R: empty-comment
2110
]

src/numpy-stubs/@test/.ruff.toml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ line-length = 88
33

44
[lint]
55
extend-ignore = [
6-
"D", # pydocstyle
7-
"ERA", # eradicate
8-
"S", # flake8-bandit
9-
"T", # flake8-print
10-
"PLR2004", # pylint: magic-value-comparisons
6+
"D", # pydocstyle
7+
"FBT", # flake8-boolean-trap
8+
"PYI054", # flake8-pyi: numeric-literal-too-long
119
]

src/numpy-stubs/@test/generated/.ruff.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@ line-length = 120
33

44
[lint]
55
extend-ignore = [
6-
"PTH", # flake8-use-pathlib
7-
"B015", # flake8-bugbear useless-comparison
86
"B018", # flake8-bugbear useless-expression
9-
"PYI015", # flake8-pyi: assignment-default-in-stub
10-
"PYI017", # flake8-pyi: complex-assignment-in-stub
11-
"SLF001", # flake8-self: private-member-access
127
"PLR0124", # pylint/R: comparison-with-itself
138
"PLC2801", # pylint/C: unnecessary-dunder-call
149
]

src/numpy-stubs/@test/runtime/.ruff.toml

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,7 @@ extend = "../.ruff.toml"
33

44
[lint]
55
extend-ignore = [
6-
"ARG", # flake8-unused-arguments
7-
"B015", # flake8-bugbear: useless-comparison
8-
"B018", # flake8-bugbear: useless-expression
9-
"DTZ001", # flake8-datetimez: call-datetime-without-tzinfo
10-
"SLF001", # flake8-self: private-member-access
11-
"TD002", # flake8-todos: missing-todo-author
12-
"PLC2801", # pylint/C: unnecessary-dunder-call
13-
"PLR0124", # pylint/R: comparison-with-itself
14-
"PLR6301", # pylint/R: no-self-use
15-
"F841", # pyflakes: unused-variable
16-
"UP018", # pyupgrade: native-literals
17-
"RUF046", # ruff: unnecessary-cast-to-int
6+
"ARG", # flake8-unused-arguments
7+
"B015", # flake8-bugbear: useless-comparison
8+
"B018", # flake8-bugbear: useless-expression
189
]

src/numpy-stubs/@test/runtime/legacy/arithmetic.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
from __future__ import annotations
2-
3-
from typing import Any
1+
from typing import Self
42

53
import pytest
64

@@ -38,28 +36,28 @@ def __array__(
3836
ret[()] = self
3937
return ret
4038

41-
def __sub__(self, value: Any) -> Object:
39+
def __sub__(self, value: object) -> Self:
4240
return self
4341

44-
def __rsub__(self, value: Any) -> Object:
42+
def __rsub__(self, value: object) -> Self:
4543
return self
4644

47-
def __floordiv__(self, value: Any) -> Object:
45+
def __floordiv__(self, value: object) -> Self:
4846
return self
4947

50-
def __rfloordiv__(self, value: Any) -> Object:
48+
def __rfloordiv__(self, value: object) -> Self:
5149
return self
5250

53-
def __mul__(self, value: Any) -> Object:
51+
def __mul__(self, value: object) -> Self:
5452
return self
5553

56-
def __rmul__(self, value: Any) -> Object:
54+
def __rmul__(self, value: object) -> Self:
5755
return self
5856

59-
def __pow__(self, value: Any) -> Object:
57+
def __pow__(self, value: object) -> Self:
6058
return self
6159

62-
def __rpow__(self, value: Any) -> Object:
60+
def __rpow__(self, value: object) -> Self:
6361
return self
6462

6563

0 commit comments

Comments
 (0)