Skip to content

Commit ffa950e

Browse files
committed
🚨 fix various ruff errors
1 parent ce1085d commit ffa950e

File tree

18 files changed

+75
-63
lines changed

18 files changed

+75
-63
lines changed

‎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/@test/runtime/legacy/comparisons.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737

3838
# Arrays
3939

40+
# ruff: noqa: PLR0124
41+
4042
AR_b > AR_b
4143
AR_b > AR_u
4244
AR_b > AR_i

‎src/numpy-stubs/@test/runtime/legacy/lib_version.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
version.pre_release
1111
version.is_devversion
1212

13+
# ruff: noqa: PLR0124
14+
1315
version == version
1416
version != version
1517
version < "1.8.0"

‎src/numpy-stubs/@test/runtime/legacy/mod.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,11 @@
4343
b_ % AR
4444

4545
divmod(b_, b_)
46-
# workarounds for https://github.com/microsoft/pyright/issues/9663
47-
b_.__divmod__(b)
48-
b_.__divmod__(i)
49-
b_.__divmod__(f)
50-
b_.__divmod__(i8)
51-
b_.__divmod__(u8)
46+
divmod(b, b)
47+
divmod(b, i)
48+
divmod(b, f)
49+
divmod(b, i8)
50+
divmod(b, u8)
5251
divmod(b_, f8)
5352
divmod(b_, AR)
5453

@@ -84,10 +83,9 @@
8483
i8 % AR
8584

8685
divmod(i8, b)
87-
# workarounds for https://github.com/microsoft/pyright/issues/9663
88-
i8.__divmod__(i)
89-
i8.__divmod__(f)
90-
i8.__divmod__(i4)
86+
divmod(i8, i)
87+
divmod(i8, f)
88+
divmod(i8, i4)
9189
divmod(i8, i8)
9290
divmod(i8, f8)
9391
divmod(i8, f4)
@@ -112,11 +110,10 @@
112110
divmod(i8, i8)
113111
divmod(f8, i8)
114112
divmod(i4, i4)
115-
# workarounds for https://github.com/microsoft/pyright/issues/9663
116-
i4.__divmod__(i8)
117-
f4.__divmod__(i8)
118-
f4.__divmod__(i4)
119-
AR.__divmod__(i8)
113+
divmod(i4, i8)
114+
divmod(f4, i8)
115+
divmod(f4, i4)
116+
divmod(AR, i8)
120117

121118
# float
122119

@@ -149,5 +146,4 @@
149146
divmod(f8, f8)
150147
divmod(f4, f8)
151148
divmod(f4, f4)
152-
# workaround for https://github.com/microsoft/pyright/issues/9663
153-
AR.__divmod__(f8)
149+
divmod(AR, f8)

‎src/numpy-stubs/@test/runtime/legacy/random.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1480,7 +1480,7 @@
14801480
random_st.randint(I_i8_low, I_i8_high_open, dtype=np.int64)
14811481
random_st.randint(-9223372036854775808, I_i8_high_open, dtype=np.int64)
14821482

1483-
bg: np.random.BitGenerator = random_st._bit_generator
1483+
bg: np.random.BitGenerator = random_st._bit_generator # noqa: SLF001
14841484

14851485
random_st.bytes(2)
14861486

‎src/numpy-stubs/@test/runtime/legacy/recfunctions.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
"""These tests are based on the doctests from `numpy/lib/recfunctions.py`."""
22

3-
from __future__ import annotations
4-
53
from typing import TYPE_CHECKING, Any, assert_type
64

75
import numpy as np
@@ -10,13 +8,15 @@
108
if TYPE_CHECKING:
119
import _numtype as _nt
1210

11+
# ruff: noqa: S101
12+
1313

1414
def test_recursive_fill_fields() -> None:
1515
a: _nt.Array[np.void] = np.array(
1616
[(1, 10.0), (2, 20.0)],
1717
dtype=[("A", np.int64), ("B", np.float64)],
1818
)
19-
b = np.zeros((int(3),), dtype=a.dtype)
19+
b = np.zeros((3,), dtype=a.dtype)
2020
out = rfn.recursive_fill_fields(a, b)
2121
assert_type(out, "_nt.Array1D[np.void]")
2222

@@ -57,16 +57,16 @@ def test_get_fieldstructure() -> None:
5757
def test_merge_arrays() -> None:
5858
assert_type(
5959
rfn.merge_arrays((
60-
np.ones((int(2),), np.int_),
61-
np.ones((int(3),), np.float64),
60+
np.ones(((2),), np.int_),
61+
np.ones(((3),), np.float64),
6262
)),
6363
"np.recarray[_nt.Rank1, np.dtype[np.void]]",
6464
)
6565

6666

6767
def test_drop_fields() -> None:
6868
ndtype = [("a", np.int64), ("b", [("b_a", np.double), ("b_b", np.int64)])]
69-
a = np.ones((int(3),), dtype=ndtype)
69+
a = np.ones(((3),), dtype=ndtype)
7070

7171
assert_type(rfn.drop_fields(a, "a"), "_nt.Array1D[np.void]")
7272
assert_type(
@@ -81,7 +81,7 @@ def test_drop_fields() -> None:
8181

8282
def test_rename_fields() -> None:
8383
ndtype = [("a", np.int64), ("b", [("b_a", np.double), ("b_b", np.int64)])]
84-
a = np.ones((int(3),), dtype=ndtype)
84+
a = np.ones(((3),), dtype=ndtype)
8585

8686
assert_type(
8787
rfn.rename_fields(a, {"a": "A", "b_b": "B_B"}),
@@ -130,11 +130,11 @@ def test_require_fields() -> None:
130130

131131

132132
def test_stack_arrays() -> None:
133-
x = np.zeros((int(2),), np.int32)
133+
x = np.zeros(((2),), np.int32)
134134
assert_type(rfn.stack_arrays(x), "_nt.Array1D[np.int32]")
135135

136-
z = np.ones((int(2),), [("A", "|S3"), ("B", float)])
137-
zz = np.ones((int(2),), [("A", "|S3"), ("B", np.float64), ("C", np.float64)])
136+
z = np.ones(((2),), [("A", "|S3"), ("B", float)])
137+
zz = np.ones(((2),), [("A", "|S3"), ("B", np.float64), ("C", np.float64)])
138138
assert_type(rfn.stack_arrays((z, zz)), "_nt.MArray[np.void]")
139139

140140

‎src/numpy-stubs/@test/runtime/legacy/scalars.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def __float__(self) -> float:
8484
np.uint64().shape
8585

8686
# Time structures
87+
# ruff: noqa: DTZ001
8788
np.datetime64()
8889
np.datetime64(0, "D")
8990
np.datetime64(0, b"D")

‎src/numpy-stubs/@test/runtime/legacy/ufunc_config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ def func3(a: str, b: int) -> int:
1515
return 0
1616

1717

18+
# ruff: noqa: PLR6301
19+
20+
1821
class Write1:
1922
def write(self, a: str) -> None:
2023
return None

0 commit comments

Comments
 (0)