Skip to content

Commit

Permalink
fix: bool<->int conversion (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
disrupted authored Jan 17, 2024
1 parent fbc0f61 commit a6015da
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
20 changes: 20 additions & 0 deletions things_cloud/models/converters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from typing import overload


@overload
def bool_int(bool_or_int: bool) -> int:
...


@overload
def bool_int(bool_or_int: int) -> bool:
...


def bool_int(bool_or_int: bool | int) -> int | bool:
if isinstance(bool_or_int, bool):
return int(bool_or_int)
else:
# bools are also ints in Python :'o
# so this has to be the else case
return bool(bool_or_int)
3 changes: 2 additions & 1 deletion things_cloud/models/todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from attrs import define, field
from cattr.gen import make_dict_structure_fn
from cattrs.gen import make_dict_unstructure_fn, override
from things_cloud.models.converters import bool_int

from things_cloud.models.serde import TodoSerde
from things_cloud.utils import Util
Expand Down Expand Up @@ -59,7 +60,7 @@ class TodoItem:
_instance_creation_paused: bool = field(default=False, kw_only=True)
_projects: list[str] = field(factory=list, kw_only=True)
_areas: list[str] = field(factory=list, kw_only=True)
_is_evening: bool = field(default=False, converter=int, kw_only=True)
_is_evening: bool = field(default=False, converter=bool_int, kw_only=True)
_tags: list[Any] = field(factory=list, kw_only=True) # TODO: set data type
_type: Type = field(default=Type.TASK, kw_only=True)
_due_date_suppression_date: datetime | None = field(default=None, kw_only=True)
Expand Down

0 comments on commit a6015da

Please sign in to comment.