Skip to content

Commit 0a7421a

Browse files
authored
Add ruff rules (#241)
1 parent 712cbf7 commit 0a7421a

File tree

16 files changed

+86
-79
lines changed

16 files changed

+86
-79
lines changed

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import data_morph
1414

1515
sys.path.insert(0, str(Path().absolute()))
16-
from post_build import determine_versions # noqa: E402
16+
from post_build import determine_versions
1717

1818
project = 'Data Morph'
1919
current_year = dt.date.today().year

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,13 @@ lint.select = [
102102
"I", # isort
103103
"N", # pep8-naming
104104
"PTH", # flake8-use-pathlib
105+
"RUF", # ruff-specific rules
105106
"SIM", # flake8-simplify
106107
"TRY", # tryceratops
107108
"UP", # pyupgrade
108109
"W", # pycodestyle warning
109110
]
110111
lint.ignore = [
111-
"ANN101", # missing type annotation for self (will be removed in future ruff version)
112-
"ANN102", # missing type annotation for cls in classmethod (will be removed in future ruff version)
113112
"E501", # line-too-long
114113
"TRY003", # avoid specifying long messages outside the exception class (revisit later and consider making custom exceptions)
115114
]

src/data_morph/bounds/bounding_box.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def __eq__(self, other: BoundingBox) -> bool:
9797
def __repr__(self) -> str:
9898
return '<BoundingBox>\n' f' x={self.x_bounds}' '\n' f' y={self.y_bounds}'
9999

100-
def adjust_bounds(self, x: Number = None, y: Number = None) -> None:
100+
def adjust_bounds(self, x: Number | None = None, y: Number | None = None) -> None:
101101
"""
102102
Adjust bounding box range.
103103

src/data_morph/data/dataset.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Class representing a dataset for morphing."""
22

3+
from __future__ import annotations
4+
35
from numbers import Number
46

57
import matplotlib.pyplot as plt
@@ -39,13 +41,13 @@ class Dataset:
3941
Utility for creating :class:`Dataset` objects from CSV files.
4042
"""
4143

42-
_REQUIRED_COLUMNS = ['x', 'y']
44+
_REQUIRED_COLUMNS = ('x', 'y')
4345

4446
def __init__(
4547
self,
4648
name: str,
4749
df: pd.DataFrame,
48-
scale: Number = None,
50+
scale: Number | None = None,
4951
) -> None:
5052
self.df: pd.DataFrame = self._validate_data(df).pipe(self._scale_data, scale)
5153
"""pandas.DataFrame: DataFrame containing columns x and y."""
@@ -181,7 +183,7 @@ def _validate_data(self, data: pd.DataFrame) -> pd.DataFrame:
181183

182184
@plot_with_custom_style
183185
def plot(
184-
self, ax: Axes = None, show_bounds: bool = True, title: str = 'default'
186+
self, ax: Axes | None = None, show_bounds: bool = True, title: str = 'default'
185187
) -> Axes:
186188
"""
187189
Plot the dataset and its bounds.

src/data_morph/data/loader.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
"""Load data for morphing."""
22

3+
from __future__ import annotations
4+
35
from importlib.resources import files
46
from itertools import zip_longest
57
from numbers import Number
68
from pathlib import Path
9+
from typing import ClassVar
710

811
import matplotlib.pyplot as plt
912
import numpy as np
@@ -41,7 +44,7 @@ class DataLoader:
4144
"""
4245

4346
_DATA_PATH: str = 'data/starter_shapes/'
44-
_DATASETS: dict = {
47+
_DATASETS: ClassVar[dict[str, str]] = {
4548
'bunny': 'bunny.csv',
4649
'cat': 'cat.csv',
4750
'dino': 'dino.csv',
@@ -66,7 +69,7 @@ def __init__(self) -> None:
6669
def load_dataset(
6770
cls,
6871
dataset: str,
69-
scale: Number = None,
72+
scale: Number | None = None,
7073
) -> Dataset:
7174
"""
7275
Load dataset.

src/data_morph/shapes/bases/line_collection.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Base class for shapes that are composed of lines."""
22

3+
from __future__ import annotations
4+
35
from collections.abc import Iterable
46
from numbers import Number
57

@@ -97,7 +99,7 @@ def distance(self, x: Number, y: Number) -> float:
9799
)
98100

99101
@plot_with_custom_style
100-
def plot(self, ax: Axes = None) -> Axes:
102+
def plot(self, ax: Axes | None = None) -> Axes:
101103
"""
102104
Plot the shape.
103105

src/data_morph/shapes/bases/point_collection.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Base class for shapes that are composed of points."""
22

3+
from __future__ import annotations
4+
35
from collections.abc import Iterable
46
from numbers import Number
57

@@ -52,7 +54,7 @@ def distance(self, x: Number, y: Number) -> float:
5254
)
5355

5456
@plot_with_custom_style
55-
def plot(self, ax: Axes = None) -> Axes:
57+
def plot(self, ax: Axes | None = None) -> Axes:
5658
"""
5759
Plot the shape.
5860

src/data_morph/shapes/bases/shape.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def _recursive_repr(self, attr: str | None = None) -> str:
103103
)
104104

105105
@abstractmethod
106-
def plot(self, ax: Axes = None) -> Axes:
106+
def plot(self, ax: Axes | None = None) -> Axes:
107107
"""
108108
Plot the shape.
109109

src/data_morph/shapes/circles.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Shapes that are circular in nature."""
22

3+
from __future__ import annotations
4+
35
from numbers import Number
46

57
import matplotlib.pyplot as plt
@@ -33,7 +35,7 @@ class Circle(Shape):
3335
The radius of the circle.
3436
"""
3537

36-
def __init__(self, dataset: Dataset, radius: Number = None) -> None:
38+
def __init__(self, dataset: Dataset, radius: Number | None = None) -> None:
3739
self.center: np.ndarray = dataset.df[['x', 'y']].mean().to_numpy()
3840
"""numpy.ndarray: The (x, y) coordinates of the circle's center."""
3941

@@ -63,7 +65,7 @@ def distance(self, x: Number, y: Number) -> float:
6365
)
6466

6567
@plot_with_custom_style
66-
def plot(self, ax: Axes = None) -> Axes:
68+
def plot(self, ax: Axes | None = None) -> Axes:
6769
"""
6870
Plot the shape.
6971
@@ -159,7 +161,7 @@ def distance(self, x: Number, y: Number) -> float:
159161
)
160162

161163
@plot_with_custom_style
162-
def plot(self, ax: Axes = None) -> Axes:
164+
def plot(self, ax: Axes | None = None) -> Axes:
163165
"""
164166
Plot the shape.
165167

src/data_morph/shapes/factory.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from itertools import zip_longest
44
from numbers import Number
5+
from typing import ClassVar
56

67
import matplotlib.pyplot as plt
78
import numpy as np
@@ -56,7 +57,7 @@ class ShapeFactory:
5657
The starting dataset to morph into other shapes.
5758
"""
5859

59-
_SHAPE_MAPPING: dict = {
60+
_SHAPE_MAPPING: ClassVar[dict[str, type[Shape]]] = {
6061
'bullseye': Bullseye,
6162
'circle': Circle,
6263
'high_lines': HighLines,

0 commit comments

Comments
 (0)