Skip to content

Commit bcf7c34

Browse files
committed
Linting and formatting to bring up to date with new use of Ruff
1 parent cb51a10 commit bcf7c34

File tree

5 files changed

+24
-52
lines changed

5 files changed

+24
-52
lines changed

archeryutils/handicaps/handicap_scheme.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def _pairwise(iterable):
5353
next(b, None)
5454
return zip(a, b)
5555

56-
itr.pairwise = _pairwise
56+
setattr(itr, "pairwise", _pairwise) # noqa: B010
5757

5858

5959
class HandicapScheme(ABC):
@@ -107,15 +107,17 @@ def __repr__(self) -> str:
107107

108108
@overload
109109
@abstractmethod
110-
def sigma_t(self, handicap: float, dist: float) -> float: ...
110+
def sigma_t(self, handicap: float, dist: float) -> float:
111+
...
111112

112113
@overload
113114
@abstractmethod
114115
def sigma_t(
115116
self,
116117
handicap: npt.NDArray[np.float64],
117118
dist: float,
118-
) -> npt.NDArray[np.float64]: ...
119+
) -> npt.NDArray[np.float64]:
120+
...
119121

120122
@abstractmethod
121123
def sigma_t(self, handicap: FloatArray, dist: float) -> FloatArray:

archeryutils/handicaps/tests/test_handicaps.py

+6-18
Original file line numberDiff line numberDiff line change
@@ -385,17 +385,13 @@ def test_different_target_faces(
385385
assert arrow_score_direct == pytest.approx(arrow_score_expected)
386386

387387
def test_empty_spec(self):
388-
"""
389-
Check expected score is zero when no target rings are defined.
390-
"""
388+
"""Check expected score is zero when no target rings are defined."""
391389
target = Target.from_spec({}, 10, 10)
392390
s_bar = hc.arrow_score(50, target, "AGB")
393391
assert s_bar == 0
394392

395393
def test_unsorted_spec(self):
396-
"""
397-
Check expected score is insensitive to order of input spec.
398-
"""
394+
"""Check expected score is insensitive to order of input spec."""
399395

400396
def _target(spec):
401397
return Target.from_spec(spec, 10, 10)
@@ -408,7 +404,7 @@ def _target(spec):
408404

409405
def test_decimal_ring_scores(self):
410406
"""
411-
Check expected score can be calculated for non integer ring scores
407+
Check expected score can be calculated for non integer ring scores.
412408
413409
Uses a target with integer ring scores at twice the value for comparison
414410
"""
@@ -421,9 +417,7 @@ def test_decimal_ring_scores(self):
421417
assert s_bar_int == 2 * s_bar_dec
422418

423419
def test_array_handicaps(self):
424-
"""
425-
Check expected score can be calculated for an array of input handicap values
426-
"""
420+
"""Check expected score can be calculated for an array of handicap values."""
427421
handicaps = np.array([10, 20, 30, 40])
428422
target = Target.from_spec({0.1: 3, 0.2: 5}, 10, 10)
429423
s_bar = hc.arrow_score(handicaps, target, "AGB")
@@ -652,10 +646,7 @@ def test_rounded_round_score(
652646
)
653647

654648
def test_calculation_custom_scoring(self):
655-
"""
656-
Check that score can be calculated for a round with custom scoring
657-
"""
658-
649+
"""Check that score can be calculated for a round with custom scoring."""
659650
assert hc.score_for_round(20.0, kings_900_rec, "AGB", None, True) == 896.0
660651

661652

@@ -913,8 +904,5 @@ def test_decimal(
913904
assert handicap == pytest.approx(handicap_expected)
914905

915906
def test_calculation_custom_scoring(self):
916-
"""
917-
Check that handicap can be calculated for a round with custom scoring
918-
"""
919-
907+
"""Check that handicap can be calculated for a round with custom scoring."""
920908
assert hc.handicap_from_score(896, kings_900_rec, "AGB", int_prec=True) == 20

archeryutils/targets.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ def __init__(
126126
distance: Union[float, tuple[float, str]],
127127
indoor: bool = False,
128128
) -> None:
129-
130129
if scoring_system not in self.supported_systems:
131130
msg = (
132131
f"""Invalid Target Face Type specified.\n"""
@@ -204,7 +203,7 @@ def from_spec(
204203
205204
Examples
206205
--------
207-
>>> #WA 18m compound triple spot
206+
>>> # WA 18m compound triple spot
208207
>>> specs = {0.02: 10, 0.08: 9, 0.12: 8, 0.16: 7, 0.2: 6}
209208
>>> target = Target.from_spec(specs, 40, 18)
210209
"""

archeryutils/tests/test_rounds.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@ def test_properties(self) -> None:
121121
assert test_pass.native_diameter_unit == "cm"
122122

123123
def test_custom_target(self) -> None:
124-
"""
125-
Check that pass can be constructed from a custom target specification
126-
"""
124+
"""Check that pass can be constructed from a custom target specification."""
127125
target = Target.from_spec({0.1: 3, 0.5: 1}, 80, (50, "yard"))
128126
test_pass = Pass(30, target)
129127
assert test_pass.target.is_custom

archeryutils/tests/test_targets.py

+11-26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Tests for Target class."""
22

3+
from typing import Final
4+
35
import pytest
46

57
from archeryutils.targets import ScoringSystem, Target
@@ -251,9 +253,7 @@ def test_min_score_invalid_face_type(self) -> None:
251253
],
252254
)
253255
def test_get_face_spec(self, scoring_system, diam) -> None:
254-
"""
255-
Check that target returns correct face specifications from supported scoring systems.
256-
"""
256+
"""Check that target returns face specs from supported scoring systems."""
257257
expected_spec = {
258258
"5_zone": {0.244: 9, 0.488: 7, 0.732: 5, 0.976: 3, 1.22: 1},
259259
"10_zone": {
@@ -281,34 +281,25 @@ def test_get_face_spec(self, scoring_system, diam) -> None:
281281

282282

283283
class TestCustomScoringTarget:
284-
"""
285-
Tests for Target class with custom scoring
286-
"""
284+
"""Tests for Target class with custom scoring."""
287285

288-
_11zone_spec = {0.02: 11, 0.04: 10, 0.8: 9, 0.12: 8, 0.16: 7, 0.2: 6}
286+
_11zone_spec: Final = {0.02: 11, 0.04: 10, 0.8: 9, 0.12: 8, 0.16: 7, 0.2: 6}
289287

290288
def test_constructor(self) -> None:
291-
"""
292-
Can initialise Target with a custom scoring system and spec
293-
"""
294-
289+
"""Can initialise Target with a custom scoring system and spec."""
295290
target = Target.from_spec({0.1: 3, 0.5: 1}, 80, (50, "yard"))
296291
assert target.distance == 50.0 * 0.9144
297292
assert target.diameter == 0.8
298293
assert target.scoring_system == "Custom"
299294
assert target.get_face_spec() == {0.1: 3, 0.5: 1}
300295

301296
def test_face_spec_units(self) -> None:
302-
"""
303-
Check custom Target can be constructed with alternative units.
304-
"""
297+
"""Check custom Target can be constructed with alternative units."""
305298
target = Target.from_spec(({10: 5, 20: 4, 30: 3}, "cm"), 50, 30)
306299
assert target.get_face_spec() == {0.1: 5, 0.2: 4, 0.3: 3}
307300

308301
def test_invalid_face_spec_units(self) -> None:
309-
"""
310-
Check custom Target cannot be constructed with unsupported units.
311-
"""
302+
"""Check custom Target cannot be constructed with unsupported units."""
312303
with pytest.raises(
313304
ValueError,
314305
# match=
@@ -333,23 +324,17 @@ def test_invalid_face_spec_units(self) -> None:
333324
],
334325
)
335326
def test_equality(self, spec, args, result) -> None:
336-
"""
337-
Check custom Target equality comparison is supported.
338-
"""
327+
"""Check custom Target equality comparison is supported."""
339328
target = Target.from_spec({0.2: 2, 0.4: 1}, 40, 20, indoor=True)
340329
comparison = target == Target.from_spec(spec, *args)
341330
assert comparison == result
342331

343332
def test_max_score(self) -> None:
344-
"""
345-
Check that Target with custom scoring system returns correct max score
346-
"""
333+
"""Check that Target with custom scoring system returns correct max score."""
347334
target = Target.from_spec(self._11zone_spec, 40, 18)
348335
assert target.max_score() == 11
349336

350337
def test_min_score(self) -> None:
351-
"""
352-
Check that Target with custom scoring system returns correct min score
353-
"""
338+
"""Check that Target with custom scoring system returns correct min score."""
354339
target = Target.from_spec(self._11zone_spec, 40, 18)
355340
assert target.min_score() == 6

0 commit comments

Comments
 (0)