Skip to content

Commit

Permalink
v0.4.2 - fix python 3.13 support
Browse files Browse the repository at this point in the history
  • Loading branch information
dudanov committed Dec 9, 2024
1 parent c83678a commit c55c265
Show file tree
Hide file tree
Showing 6 changed files with 945 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ ipython_config.py
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
poetry.lock
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
Expand Down
927 changes: 927 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions pyftms/models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import dataclasses as dc
import io
from enum import STRICT, IntEnum, auto
from typing import Any, Generic, TypeVar, cast, override
from typing import Any, cast, override

from ..serializer import BaseModel, ModelMeta, model_meta

Expand Down Expand Up @@ -75,11 +75,8 @@ class IndoorBikeSimulationParameters(BaseModel):
"""


T = TypeVar("T", bound=int)


@dc.dataclass(frozen=True)
class CodeSwitchModel(Generic[T], BaseModel):
class CodeSwitchModel[T: int](BaseModel):
"""Base model based on a code attribute and associated parameter attributes."""

code: T | None = dc.field(
Expand Down
16 changes: 8 additions & 8 deletions pyftms/serializer/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ def _get_model_field_serializer(field: dc.Field):
raise TypeError("'TypeVar' must have bound type.")

def _get_serializer(type_) -> Serializer:
if isinstance(type_, GenericAlias):
if (num := meta.get("num")) is None:
raise TypeError("Number of elements is required.")

serializer = _get_serializer(get_args(type_)[0])

return ListSerializer(serializer, num)

if issubclass(type_, (int, float)):
if fmt := meta.get("format"):
return get_serializer(fmt)
Expand All @@ -75,14 +83,6 @@ def _get_serializer(type_) -> Serializer:
if issubclass(type_, BaseModel):
return get_serializer(type_)

if isinstance(type_, GenericAlias):
if (num := meta.get("num")) is None:
raise TypeError("Number of elements is required.")

serializer = _get_serializer(get_args(type_)[0])

return ListSerializer(serializer, num)

raise TypeError("Unsupported type.")

return _get_serializer(type_)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pyftms"
version = "0.4.1"
version = "0.4.2"
description = "PyFTMS - Python Fitness Machine Service client library."
authors = ["Sergey V. DUDANOV <[email protected]>"]
readme = "README.md"
Expand Down
7 changes: 6 additions & 1 deletion tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from pyftms.models import TreadmillData
from pyftms.models import MachineStatusModel, TreadmillData
from pyftms.serializer import BaseModel, ModelSerializer, get_serializer


Expand Down Expand Up @@ -31,6 +31,11 @@
"energy_per_minute": 0,
},
),
(
MachineStatusModel,
b"\x05\x69\x00",
{"code": 5, "target_speed": 1.05},
),
],
)
def test_realtime_data(model: type[BaseModel], data: bytes, result: dict):
Expand Down

0 comments on commit c55c265

Please sign in to comment.