Skip to content

Commit c31c694

Browse files
.
1 parent 1e24b26 commit c31c694

File tree

8 files changed

+45
-24
lines changed

8 files changed

+45
-24
lines changed

.ruff.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,15 @@ lines-after-imports = 2 # https://docs.astral.sh/ruff/settings/#lint_isort_l
102102

103103
# https://docs.astral.sh/ruff/rules/#flake8-boolean-trap-fbt
104104
"FBT003", # Boolean positional value in function call
105+
106+
# https://docs.astral.sh/ruff/rules/#flake8-unused-arguments-arg
107+
"ARG001", # Unused function argument {name}
108+
"ARG002", # Unused method argument {name}
109+
"ARG003", # Unused class method argument: {name}
110+
"ARG004", # Unused static method argument: {name}
111+
"ARG005", # Unused lambda argument: {name}
112+
]
113+
114+
"src/pyartnet/*" = [
115+
"PLR2004" # Magic value used in comparison, consider replacing `0.01` with a constant variable
105116
]

src/pyartnet/base/background_task.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@ def __init__(self, coro: Callable[[], Coroutine], name: str) -> None:
3030
self.name: Final = name
3131
self.task: Task | None = None
3232

33-
def start(self):
33+
def start(self) -> None:
3434
if self.task is not None:
3535
return None
3636

3737
self.task = task = CREATE_TASK(self.coro_wrap(), name=self.name)
3838
_BACKGROUND_TASKS.add(task)
3939
task.add_done_callback(_BACKGROUND_TASKS.discard)
40+
return None
4041

41-
def cancel(self):
42+
def cancel(self) -> None:
4243
if self.task is None:
4344
return None
4445

src/pyartnet/base/channel.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
import logging
44
import warnings
55
from array import array
6-
from collections.abc import Callable, Collection
76
from logging import DEBUG as LVL_DEBUG
87
from math import ceil
9-
from typing import TYPE_CHECKING, Any, Final, Literal, Union
8+
from typing import TYPE_CHECKING, Any, Final, Generator, Literal
109

10+
from typing_extensions import Self
11+
12+
from pyartnet.base.channel_fade import ChannelBoundFade
13+
from pyartnet.base.output_correction import OutputCorrection
1114
from pyartnet.errors import (
1215
ChannelOutOfUniverseError,
1316
ChannelValueOutOfBoundsError,
@@ -17,11 +20,10 @@
1720
from pyartnet.fades import FadeBase, LinearFade
1821
from pyartnet.output_correction import linear
1922

20-
from .channel_fade import ChannelBoundFade
21-
from .output_correction import OutputCorrection
22-
2323

2424
if TYPE_CHECKING:
25+
from collections.abc import Callable, Collection
26+
2527
from .universe import BaseUniverse
2628

2729

@@ -93,7 +95,7 @@ def __init__(self, universe: BaseUniverse,
9395
# Callbacks
9496
self.callback_fade_finished: Callable[[Channel], Any] | None = None
9597

96-
def _apply_output_correction(self):
98+
def _apply_output_correction(self) -> None:
9799
# default correction is linear
98100
self._correction_current = linear
99101

@@ -102,6 +104,7 @@ def _apply_output_correction(self):
102104
if obj._correction_output is not None:
103105
self._correction_current = obj._correction_output
104106
return None
107+
return None
105108

106109
def get_values(self) -> list[int]:
107110
"""Get the current (uncorrected) channel values
@@ -110,7 +113,7 @@ def get_values(self) -> list[int]:
110113
"""
111114
return self._values_raw.tolist()
112115

113-
def set_values(self, values: Collection[Union[int, float]]):
116+
def set_values(self, values: Collection[int | float]) -> Self:
114117
"""Set values for a channel without a fade
115118
116119
:param values: Iterable of values with the same size as the channel width
@@ -141,7 +144,7 @@ def set_values(self, values: Collection[Union[int, float]]):
141144
self._parent_universe.channel_changed(self)
142145
return self
143146

144-
def to_buffer(self, buf: bytearray):
147+
def to_buffer(self, buf: bytearray) -> Self:
145148
byte_order = self._byte_order
146149
byte_size = self._byte_size
147150

@@ -151,15 +154,17 @@ def to_buffer(self, buf: bytearray):
151154
start += byte_size
152155
return self
153156

154-
def add_fade(self, values: Collection[Union[int, FadeBase]], duration_ms: int,
155-
fade_class: type[FadeBase] = LinearFade):
157+
def add_fade(self, values: Collection[int | FadeBase], duration_ms: int,
158+
fade_class: type[FadeBase] = LinearFade) -> Self:
156159
warnings.warn(
157-
f'{self.set_fade.__name__:s} is deprecated, use {self.set_fade.__name__:s} instead', DeprecationWarning)
160+
f'{self.set_fade.__name__:s} is deprecated, use {self.set_fade.__name__:s} instead',
161+
DeprecationWarning, stacklevel=2
162+
)
158163
return self.set_fade(values, duration_ms, fade_class)
159164

160165
# noinspection PyProtectedMember
161-
def set_fade(self, values: Collection[Union[int, FadeBase]], duration_ms: int,
162-
fade_class: type[FadeBase] = LinearFade):
166+
def set_fade(self, values: Collection[int | FadeBase], duration_ms: int,
167+
fade_class: type[FadeBase] = LinearFade) -> Self:
163168
"""Add and schedule a new fade for the channel
164169
165170
:param values: Target values for the fade
@@ -207,7 +212,7 @@ def set_fade(self, values: Collection[Union[int, FadeBase]], duration_ms: int,
207212
log.debug(f'CH {self._start + i}: {fade.debug_initialize():s}')
208213
return self
209214

210-
def __await__(self):
215+
def __await__(self) -> Generator[None, None, bool]:
211216
if self._current_fade is None:
212217
return False
213218
yield from self._current_fade.event.wait().__await__()

src/pyartnet/fades/fade_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class FadeBase:
44
def __init__(self) -> None:
55
self.is_done = False
66

7-
def initialize(self, current: int, target: int, steps: int):
7+
def initialize(self, current: int, target: int, steps: int) -> None:
88
raise NotImplementedError()
99

1010
def debug_initialize(self) -> str:

src/pyartnet/fades/fade_linear.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from typing_extensions import override
2+
13
from .fade_base import FadeBase
24

35

@@ -9,14 +11,17 @@ def __init__(self) -> None:
911
self.current: float = 0.0 # Current Value
1012
self.factor: float = 1.0
1113

14+
@override
1215
def debug_initialize(self) -> str:
1316
return f'{self.current:03.0f} -> {self.target:03d} | step: {self.factor:+5.1f}'
1417

18+
@override
1519
def initialize(self, start: int, target: int, steps: int) -> None:
1620
self.current = start
1721
self.target = target
1822
self.factor = (self.target - start) / steps
1923

24+
@override
2025
def calc_next_value(self) -> float:
2126
self.current += self.factor
2227

src/pyartnet/output_correction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
def linear(val: float, max_val: int = 0xFF) -> float:
1+
def linear(val: float, max_val: int = 0xFF) -> float: # noqa: ARG001
22
"""linear output correction"""
33
return val
44

tests/channel/test_boundaries.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def get_node_universe_mock():
5050
((1, 1, -1, 255), (1, 1, 256, 255), (3, 1, 256, 255),
5151
(1, 2, -1, 65535), (1, 2, 65536, 65535), (3, 2, 65536, 65535), ))
5252
def test_set_invalid(width, byte_size, invalid, valid) -> None:
53-
node, universe = get_node_universe_mock()
53+
_, universe = get_node_universe_mock()
5454

5555
invalid_values = [0] * (width - 1) + [invalid]
5656
valid_values = [0] * (width - 1) + [valid]
@@ -71,7 +71,7 @@ def test_set_invalid(width, byte_size, invalid, valid) -> None:
7171

7272

7373
async def test_set_missing() -> None:
74-
node, universe = get_node_universe_mock()
74+
_, universe = get_node_universe_mock()
7575

7676
c = Channel(universe, 1, 1)
7777
with pytest.raises(ValueCountDoesNotMatchChannelWidthError) as e:

tests/conftest.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,12 @@ def test_patched_socket(patched_socket) -> None:
5555
assert node._socket.sendto is patched_socket
5656

5757

58-
@pytest.fixture()
58+
@pytest.fixture
5959
def node():
60-
node = TestingNode('IP', 9999)
61-
return node
60+
return TestingNode('IP', 9999)
6261

6362

64-
@pytest.fixture()
63+
@pytest.fixture
6564
def universe(node: BaseNode):
6665
return node.add_universe()
6766

0 commit comments

Comments
 (0)