Skip to content

Commit

Permalink
Use from __future__ import annotations (#429)
Browse files Browse the repository at this point in the history
Always use cls in classmethods and return Self
  • Loading branch information
Kane610 authored Mar 31, 2024
1 parent 98ae247 commit 3144923
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions axis/models/light_control.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Light Control API data model."""

from __future__ import annotations

from dataclasses import dataclass
from typing import NotRequired, Self

Expand Down Expand Up @@ -225,14 +227,14 @@ class Range:
high: int

@classmethod
def from_dict(cls, data: RangeT) -> "Range":
def from_dict(cls, data: RangeT) -> Self:
"""Create range object from dict."""
return Range(low=data["low"], high=data["high"])
return cls(low=data["low"], high=data["high"])

@classmethod
def from_list(cls, data: list[RangeT]) -> list["Range"]:
def from_list(cls, data: list[RangeT]) -> list[Self]:
"""Create range object from dict."""
return [Range.from_dict(range) for range in data]
return [cls.from_dict(range) for range in data]


@dataclass
Expand Down Expand Up @@ -294,9 +296,9 @@ class ServiceCapabilities:
day_night_synchronize_support: bool

@classmethod
def from_dict(cls, data: ServiceCapabilitiesT) -> "ServiceCapabilities":
def from_dict(cls, data: ServiceCapabilitiesT) -> Self:
"""Create service capabilities object from dict."""
return ServiceCapabilities(
return cls(
automatic_intensity_support=data["automaticIntensitySupport"],
manual_intensity_support=data["manualIntensitySupport"],
get_current_intensity_support=data["getCurrentIntensitySupport"],
Expand Down

0 comments on commit 3144923

Please sign in to comment.