Skip to content

Commit 4b2ce8c

Browse files
committed
✨ Add type hints and improve compatibility with Python 3.11+
Add proper type annotations throughout the codebase for Python 3.11+ - Implement PEP 604 style type hints (T | None) where appropriate - Add comprehensive typing to CLI functions for better IDE support - Fix potential edge cases in gradient text rendering - Add missing types in client and effect_cycler example - Replace class attribute access with safer optional checks - Include types-requests for better type checking compatibility - Fix version in __init__.py to match current release - Add proper type annotations in tests with cast() for JSON data
1 parent 1944f9c commit 4b2ce8c

File tree

9 files changed

+162
-89
lines changed

9 files changed

+162
-89
lines changed

examples/effect_cycler.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import time
44

55
from signalrgb.client import SignalRGBClient, SignalRGBException
6+
from signalrgb.model import Effect
67

78

8-
def cycle_effects(client, duration=10):
9+
def cycle_effects(client: SignalRGBClient, duration: int = 10) -> None:
910
"""
1011
Cycle through all available effects, applying each for a specified duration.
1112
@@ -25,13 +26,13 @@ def cycle_effects(client, duration=10):
2526
logging.warning("Failed to apply effect %s: %s", effect_name, e)
2627

2728

28-
def main():
29+
def main() -> None:
2930
# Initialize the SignalRGB client
3031
client = SignalRGBClient(host="hyperia.home", port=16038)
3132
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
3233

3334
# Initialize initial_effect to None
34-
initial_effect = None
35+
initial_effect: Effect | None = None
3536

3637
try:
3738
# Get the initial effect

pyproject.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name = "signalrgb"
33
version = "0.9.7"
44
description = "A Python client for SignalRGB"
55
readme = "README.md"
6-
requires-python = ">=3.9"
6+
requires-python = ">=3.11"
77
license = { text = "Apache-2.0" }
88
authors = [{ name = "Stefanie Jane", email = "[email protected]" }]
99
dependencies = [
@@ -25,6 +25,7 @@ dev = [
2525
"mkdocstrings[python]>=0.29.0",
2626
"mypy>=1.15.0",
2727
"pytest-cov>=6.0.0",
28+
"types-requests>=2.31.0.6",
2829
"types-setuptools>=75.8.2.20250305",
2930
"semver>=3.0.4",
3031
]
@@ -63,7 +64,7 @@ exclude_lines = [
6364

6465
# Type checking configuration
6566
[tool.mypy]
66-
python_version = "3.9"
67+
python_version = "3.11"
6768
# Basic type checking
6869
warn_return_any = true
6970
warn_unused_configs = true
@@ -110,7 +111,7 @@ check_untyped_defs = false
110111
[tool.ruff]
111112
# General settings
112113
line-length = 120
113-
target-version = "py39"
114+
target-version = "py311"
114115
src = ["signalrgb", "tests"]
115116
extend-exclude = [".venv", "docs"]
116117

@@ -241,7 +242,7 @@ docstring-code-line-length = 80
241242

242243
# Pylint configuration - only for things Ruff can't handle
243244
[tool.pylint]
244-
py-version = "3.9"
245+
py-version = "3.11"
245246
jobs = 2
246247
max-line-length = 120
247248
disable = [

scripts/release.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def check_tool_installed(tool_name: str) -> None:
162162
sys.exit(1)
163163

164164

165-
def run_git_command(args: list[str], check: bool = False) -> subprocess.CompletedProcess:
165+
def run_git_command(args: list[str], check: bool = False) -> subprocess.CompletedProcess[str]:
166166
"""Run a git command safely.
167167
168168
This centralizes all git subprocess calls and ensures they're done properly.
@@ -219,7 +219,7 @@ def get_current_version() -> str:
219219

220220
with open("pyproject.toml", "rb") as f:
221221
config = tomllib.load(f)
222-
return config["project"]["version"]
222+
return str(config["project"]["version"])
223223

224224

225225
def update_version(new_version: str) -> None:

signalrgb/__init__.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,29 @@
11
"""Base package for signalrgb-python"""
2+
3+
from typing import Any, Literal, Optional, Union, cast
4+
5+
from .client import (
6+
APIError,
7+
NotFoundError,
8+
SignalRGBClient,
9+
SignalRGBConnectionError,
10+
SignalRGBError,
11+
)
12+
from .model import (
13+
Effect,
14+
EffectPreset,
15+
Layout,
16+
)
17+
18+
__version__ = "0.1.0"
19+
20+
__all__ = [
21+
"APIError",
22+
"Effect",
23+
"EffectPreset",
24+
"Layout",
25+
"NotFoundError",
26+
"SignalRGBClient",
27+
"SignalRGBConnectionError",
28+
"SignalRGBError",
29+
]

0 commit comments

Comments
 (0)