Skip to content

Commit

Permalink
chore: Make type hints more backwards-compatible
Browse files Browse the repository at this point in the history
Signed-off-by: Kai Blin <[email protected]>
  • Loading branch information
kblin committed Dec 21, 2022
1 parent f6cdb96 commit 788a97b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
5 changes: 3 additions & 2 deletions antismash_models/base.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""Base Redis<->Python object mapper"""
from __future__ import annotations
from datetime import datetime
import json
from typing import Any, Type, TypeVar
from typing import Any, Type, TypeVar, Union

from redis import Redis as SyncRedis
from redis.asyncio import Redis as AsyncRedis

DataBase = SyncRedis | AsyncRedis
DataBase = Union[SyncRedis, AsyncRedis]
TMapper = TypeVar("TMapper", bound="BaseMapper")


Expand Down
1 change: 1 addition & 0 deletions antismash_models/control.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""antiSMASH worker control abstraction"""
from __future__ import annotations
from functools import wraps
from .base import BaseMapper, DataBase, async_mixin, sync_mixin

Expand Down
15 changes: 8 additions & 7 deletions antismash_models/job.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""antiSMASH job abstraction"""
from __future__ import annotations
from datetime import datetime
import string
from typing import Any, Type, TypeVar
from typing import Any, Type, TypeVar, Union

from .base import BaseMapper, DataBase, async_mixin, sync_mixin

Expand Down Expand Up @@ -165,10 +166,10 @@ def __init__(self, db: DataBase, job_id: str) -> None:
self._state: str = 'created'
self._molecule_type: str = 'nucl'
self._genefinder: str = 'none'
self._hmmdetection_strictness: str | None = None
self._sideload_simple: str | None = None
self._hmmdetection_strictness: Union[str, None] = None
self._sideload_simple: Union[str, None] = None
self.status: str = 'pending'
self.original_id: str | None = None
self.original_id: Union[str, None] = None

# Regular attributes that differ from None
self.added: datetime = datetime.utcnow()
Expand Down Expand Up @@ -202,7 +203,7 @@ def state(self) -> str:
return self._state

@state.setter
def state(self, value: str | None) -> None:
def state(self, value: Union[str, None]) -> None:
if value is None:
self._legacy = True
return
Expand Down Expand Up @@ -262,7 +263,7 @@ def genefinding(self, value) -> None:
self.genefinder = value

@property
def hmmdetection_strictness(self) -> str | None:
def hmmdetection_strictness(self) -> Union[str, None]:
return self._hmmdetection_strictness

@hmmdetection_strictness.setter
Expand All @@ -273,7 +274,7 @@ def hmmdetection_strictness(self, value: str) -> None:
self._hmmdetection_strictness = value

@property
def sideload_simple(self) -> str | None:
def sideload_simple(self) -> Union[str, None]:
return self._sideload_simple

@sideload_simple.setter
Expand Down
7 changes: 4 additions & 3 deletions antismash_models/notice.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""antiSMASH notice abstraction"""
from __future__ import annotations
from datetime import datetime, timedelta
from functools import wraps
from typing import TypeVar
from typing import TypeVar, Union

from .base import BaseMapper, DataBase, async_mixin, sync_mixin

Expand Down Expand Up @@ -45,8 +46,8 @@ class BaseNotice(BaseMapper):

def __init__(self, db: DataBase, notice_id: str, *, category: str = "info",
teaser: str = "placeholder", text: str = "placeholder",
show_from: datetime | None = None,
show_until: datetime | None = None):
show_from: Union[datetime, None] = None,
show_until: Union[datetime, None] = None):
super(BaseNotice, self).__init__(db, "notice:{}".format(notice_id))
self._id: str = notice_id
self.category = category
Expand Down

0 comments on commit 788a97b

Please sign in to comment.