Skip to content

Commit d51c277

Browse files
authored
Merge pull request #37 from asmeurer/ruff
Set up ruff linting
2 parents a940cb1 + edd87f0 commit d51c277

14 files changed

+58
-23
lines changed

.github/workflows/ruff.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: CI
2+
on: [push, pull_request]
3+
jobs:
4+
check-ruff:
5+
runs-on: ubuntu-latest
6+
continue-on-error: true
7+
steps:
8+
- uses: actions/checkout@v4
9+
- name: Install Python
10+
uses: actions/setup-python@v5
11+
with:
12+
python-version: "3.11"
13+
- name: Install dependencies
14+
run: |
15+
python -m pip install --upgrade pip
16+
pip install ruff
17+
# Update output format to enable automatic inline annotations.
18+
- name: Run Ruff
19+
run: ruff check --output-format=github .

array_api_strict/_array_object.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@
3333
)
3434
from ._flags import get_array_api_strict_flags, set_array_api_strict_flags
3535

36-
from typing import TYPE_CHECKING, Optional, Tuple, Union, Any, SupportsIndex
36+
from typing import TYPE_CHECKING, SupportsIndex
3737
import types
3838

3939
if TYPE_CHECKING:
40-
from ._typing import Any, PyCapsule, Device, Dtype
40+
from typing import Optional, Tuple, Union, Any
41+
from ._typing import PyCapsule, Device, Dtype
4142
import numpy.typing as npt
4243

4344
import numpy as np
@@ -589,8 +590,8 @@ def __getitem__(
589590
key: Union[
590591
int,
591592
slice,
592-
ellipsis,
593-
Tuple[Union[int, slice, ellipsis, None], ...],
593+
ellipsis, # noqa: F821
594+
Tuple[Union[int, slice, ellipsis, None], ...], # noqa: F821
594595
Array,
595596
],
596597
/,
@@ -780,7 +781,7 @@ def __rshift__(self: Array, other: Union[int, Array], /) -> Array:
780781
def __setitem__(
781782
self,
782783
key: Union[
783-
int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], Array
784+
int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], Array # noqa: F821
784785
],
785786
value: Union[int, float, bool, Array],
786787
/,

array_api_strict/_data_type_functions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
)
1616

1717
from dataclasses import dataclass
18-
from typing import TYPE_CHECKING, List, Tuple, Union
18+
from typing import TYPE_CHECKING
1919

2020
if TYPE_CHECKING:
21+
from typing import List, Tuple, Union
2122
from ._typing import Dtype
22-
from collections.abc import Sequence
2323

2424
import numpy as np
2525

array_api_strict/_indexing_functions.py

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
from ._array_object import Array
44
from ._dtypes import _integer_dtypes
55

6+
from typing import TYPE_CHECKING
7+
8+
if TYPE_CHECKING:
9+
from typing import Optional
10+
611
import numpy as np
712

813
def take(x: Array, indices: Array, /, *, axis: Optional[int] = None) -> Array:

array_api_strict/_manipulation_functions.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
from ._array_object import Array
44
from ._data_type_functions import result_type
55

6-
from typing import List, Optional, Tuple, Union
6+
from typing import TYPE_CHECKING
7+
8+
if TYPE_CHECKING:
9+
from typing import List, Optional, Tuple, Union
710

811
import numpy as np
912

@@ -57,7 +60,7 @@ def reshape(x: Array,
5760
/,
5861
shape: Tuple[int, ...],
5962
*,
60-
copy: Optional[Bool] = None) -> Array:
63+
copy: Optional[bool] = None) -> Array:
6164
"""
6265
Array API compatible wrapper for :py:func:`np.reshape <numpy.reshape>`.
6366

array_api_strict/_searching_functions.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
from ._dtypes import _result_type, _real_numeric_dtypes
55
from ._flags import requires_data_dependent_shapes
66

7-
from typing import Optional, Tuple
7+
from typing import TYPE_CHECKING
8+
if TYPE_CHECKING:
9+
from typing import Optional, Tuple
810

911
import numpy as np
1012

array_api_strict/_statistical_functions.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
_numeric_dtypes,
77
)
88
from ._array_object import Array
9-
from ._dtypes import float32, float64, complex64, complex128
9+
from ._dtypes import float32, complex64
1010

11-
from typing import TYPE_CHECKING, Optional, Tuple, Union
11+
from typing import TYPE_CHECKING
1212

1313
if TYPE_CHECKING:
14+
from typing import Optional, Tuple, Union
1415
from ._typing import Dtype
1516

1617
import numpy as np

array_api_strict/_typing.py

-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121

2222
from typing import (
2323
Any,
24-
Literal,
25-
Sequence,
26-
Type,
27-
Union,
2824
TypeVar,
2925
Protocol,
3026
)

array_api_strict/_utility_functions.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
from ._array_object import Array
44

5-
from typing import Optional, Tuple, Union
5+
from typing import TYPE_CHECKING
6+
if TYPE_CHECKING:
7+
from typing import Optional, Tuple, Union
68

79
import numpy as np
810

array_api_strict/fft.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from __future__ import annotations
22

3-
from typing import TYPE_CHECKING, Union, Optional, Literal
3+
from typing import TYPE_CHECKING
44

55
if TYPE_CHECKING:
6+
from typing import Union, Optional, Literal
67
from ._typing import Device
78
from collections.abc import Sequence
89

array_api_strict/linalg.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
_floating_dtypes,
55
_numeric_dtypes,
66
float32,
7-
float64,
87
complex64,
98
complex128,
109
)
@@ -160,7 +159,7 @@ def inv(x: Array, /) -> Array:
160159
# -np.inf, 'fro', 'nuc']]], but Literal does not support floating-point
161160
# literals.
162161
@requires_extension('linalg')
163-
def matrix_norm(x: Array, /, *, keepdims: bool = False, ord: Optional[Union[int, float, Literal['fro', 'nuc']]] = 'fro') -> Array:
162+
def matrix_norm(x: Array, /, *, keepdims: bool = False, ord: Optional[Union[int, float, Literal['fro', 'nuc']]] = 'fro') -> Array: # noqa: F821
164163
"""
165164
Array API compatible wrapper for :py:func:`np.linalg.norm <numpy.linalg.norm>`.
166165
@@ -252,7 +251,7 @@ def pinv(x: Array, /, *, rtol: Optional[Union[float, Array]] = None) -> Array:
252251
return Array._new(np.linalg.pinv(x._array, rcond=rtol))
253252

254253
@requires_extension('linalg')
255-
def qr(x: Array, /, *, mode: Literal['reduced', 'complete'] = 'reduced') -> QRResult:
254+
def qr(x: Array, /, *, mode: Literal['reduced', 'complete'] = 'reduced') -> QRResult: # noqa: F821
256255
"""
257256
Array API compatible wrapper for :py:func:`np.linalg.qr <numpy.linalg.qr>`.
258257

array_api_strict/tests/test_array_object.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import numpy as np
55
import pytest
66

7-
from .. import ones, asarray, reshape, result_type, all, equal
7+
from .. import ones, asarray, result_type, all, equal
88
from .._array_object import Array, CPU_DEVICE
99
from .._dtypes import (
1010
_all_dtypes,

array_api_strict/tests/test_manipulation_functions.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from numpy.testing import assert_raises
22
import numpy as np
33

4-
from .. import all
54
from .._creation_functions import asarray
65
from .._dtypes import float64, int8
76
from .._manipulation_functions import (

ruff.toml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[lint]
2+
ignore = [
3+
# Ignore module import not at top of file
4+
"E402",
5+
# Annoying style checks
6+
"E7",
7+
]

0 commit comments

Comments
 (0)