Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up ruff linting #37

Merged
merged 5 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: CI
on: [push, pull_request]
jobs:
check-ruff:
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v4
- name: Install Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ruff
# Update output format to enable automatic inline annotations.
- name: Run Ruff
run: ruff check --output-format=github .
11 changes: 6 additions & 5 deletions array_api_strict/_array_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@
)
from ._flags import get_array_api_strict_flags, set_array_api_strict_flags

from typing import TYPE_CHECKING, Optional, Tuple, Union, Any, SupportsIndex
from typing import TYPE_CHECKING, SupportsIndex
import types

if TYPE_CHECKING:
from ._typing import Any, PyCapsule, Device, Dtype
from typing import Optional, Tuple, Union, Any
from ._typing import PyCapsule, Device, Dtype
import numpy.typing as npt

import numpy as np
Expand Down Expand Up @@ -589,8 +590,8 @@ def __getitem__(
key: Union[
int,
slice,
ellipsis,
Tuple[Union[int, slice, ellipsis, None], ...],
ellipsis, # noqa: F821
Tuple[Union[int, slice, ellipsis, None], ...], # noqa: F821
Array,
],
/,
Expand Down Expand Up @@ -780,7 +781,7 @@ def __rshift__(self: Array, other: Union[int, Array], /) -> Array:
def __setitem__(
self,
key: Union[
int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], Array
int, slice, ellipsis, Tuple[Union[int, slice, ellipsis], ...], Array # noqa: F821
],
value: Union[int, float, bool, Array],
/,
Expand Down
4 changes: 2 additions & 2 deletions array_api_strict/_data_type_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
)

from dataclasses import dataclass
from typing import TYPE_CHECKING, List, Tuple, Union
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import List, Tuple, Union
from ._typing import Dtype
from collections.abc import Sequence

import numpy as np

Expand Down
5 changes: 5 additions & 0 deletions array_api_strict/_indexing_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
from ._array_object import Array
from ._dtypes import _integer_dtypes

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Optional

import numpy as np

def take(x: Array, indices: Array, /, *, axis: Optional[int] = None) -> Array:
Expand Down
7 changes: 5 additions & 2 deletions array_api_strict/_manipulation_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
from ._array_object import Array
from ._data_type_functions import result_type

from typing import List, Optional, Tuple, Union
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import List, Optional, Tuple, Union

import numpy as np

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

Expand Down
4 changes: 3 additions & 1 deletion array_api_strict/_searching_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
from ._dtypes import _result_type, _real_numeric_dtypes
from ._flags import requires_data_dependent_shapes

from typing import Optional, Tuple
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from typing import Optional, Tuple

import numpy as np

Expand Down
5 changes: 3 additions & 2 deletions array_api_strict/_statistical_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
_numeric_dtypes,
)
from ._array_object import Array
from ._dtypes import float32, float64, complex64, complex128
from ._dtypes import float32, complex64

from typing import TYPE_CHECKING, Optional, Tuple, Union
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Optional, Tuple, Union
from ._typing import Dtype

import numpy as np
Expand Down
4 changes: 0 additions & 4 deletions array_api_strict/_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@

from typing import (
Any,
Literal,
Sequence,
Type,
Union,
TypeVar,
Protocol,
)
Expand Down
4 changes: 3 additions & 1 deletion array_api_strict/_utility_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

from ._array_object import Array

from typing import Optional, Tuple, Union
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from typing import Optional, Tuple, Union

import numpy as np

Expand Down
3 changes: 2 additions & 1 deletion array_api_strict/fft.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from __future__ import annotations

from typing import TYPE_CHECKING, Union, Optional, Literal
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from typing import Union, Optional, Literal
from ._typing import Device
from collections.abc import Sequence

Expand Down
5 changes: 2 additions & 3 deletions array_api_strict/linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
_floating_dtypes,
_numeric_dtypes,
float32,
float64,
complex64,
complex128,
)
Expand Down Expand Up @@ -160,7 +159,7 @@ def inv(x: Array, /) -> Array:
# -np.inf, 'fro', 'nuc']]], but Literal does not support floating-point
# literals.
@requires_extension('linalg')
def matrix_norm(x: Array, /, *, keepdims: bool = False, ord: Optional[Union[int, float, Literal['fro', 'nuc']]] = 'fro') -> Array:
def matrix_norm(x: Array, /, *, keepdims: bool = False, ord: Optional[Union[int, float, Literal['fro', 'nuc']]] = 'fro') -> Array: # noqa: F821
"""
Array API compatible wrapper for :py:func:`np.linalg.norm <numpy.linalg.norm>`.

Expand Down Expand Up @@ -252,7 +251,7 @@ def pinv(x: Array, /, *, rtol: Optional[Union[float, Array]] = None) -> Array:
return Array._new(np.linalg.pinv(x._array, rcond=rtol))

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

Expand Down
2 changes: 1 addition & 1 deletion array_api_strict/tests/test_array_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
import pytest

from .. import ones, asarray, reshape, result_type, all, equal
from .. import ones, asarray, result_type, all, equal
from .._array_object import Array, CPU_DEVICE
from .._dtypes import (
_all_dtypes,
Expand Down
1 change: 0 additions & 1 deletion array_api_strict/tests/test_manipulation_functions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from numpy.testing import assert_raises
import numpy as np

from .. import all
from .._creation_functions import asarray
from .._dtypes import float64, int8
from .._manipulation_functions import (
Expand Down
7 changes: 7 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[lint]
ignore = [
# Ignore module import not at top of file
"E402",
# Annoying style checks
"E7",
]
Loading