Skip to content

Commit

Permalink
Typing fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
akadlec committed Nov 17, 2021
1 parent e7cb8d5 commit dd5e84a
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ jobs:

strategy:
matrix:
python: ["3.7", "3.8", "3.9"]
python: ["3.7", "3.8", "3.9", "3.10"]
operating-system: ["ubuntu-latest"]
installable: ["wheel", "sdist"]

Expand Down
2 changes: 1 addition & 1 deletion redisdb_exchange_plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
Redis DB exchange plugin
"""

__version__ = "0.2.2"
__version__ = "0.2.3"
12 changes: 6 additions & 6 deletions redisdb_exchange_plugin/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# Library dependencies
import json
import uuid
from typing import Dict
from typing import Dict, Optional
from modules_metadata.routing import RoutingKey
from modules_metadata.types import ModuleOrigin
from redis import Redis
Expand All @@ -43,7 +43,7 @@ class RedisClient:
"""
__redis_client: Redis

__pub_sub: PubSub or None = None
__pub_sub: Optional[PubSub] = None

__identifier: str
__channel_name: str
Expand All @@ -58,8 +58,8 @@ def __init__( # pylint: disable=too-many-arguments
port: int,
channel_name: str,
logger: Logger,
username: str or None = None,
password: str or None = None,
username: Optional[str] = None,
password: Optional[str] = None,
) -> None:
self.__redis_client = Redis(
host=host,
Expand All @@ -75,7 +75,7 @@ def __init__( # pylint: disable=too-many-arguments

# -----------------------------------------------------------------------------

def publish(self, origin: ModuleOrigin, routing_key: RoutingKey, data: Dict or None) -> None:
def publish(self, origin: ModuleOrigin, routing_key: RoutingKey, data: Optional[Dict]) -> None:
"""Publish message to default exchange channel"""
message: dict = {
"routing_key": routing_key.value,
Expand Down Expand Up @@ -128,7 +128,7 @@ def unsubscribe(self) -> None:

# -----------------------------------------------------------------------------

def receive(self) -> Dict or None:
def receive(self) -> Optional[Dict]:
"""Try to receive new message from exchange"""
result = self.__pub_sub.get_message()

Expand Down
16 changes: 8 additions & 8 deletions redisdb_exchange_plugin/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import json
import logging
import time
from typing import Dict
from typing import Dict, Optional
from threading import Thread
from kink import inject
from exchange_plugin.consumer import IConsumer
Expand Down Expand Up @@ -53,7 +53,7 @@ class RedisExchange(Thread):
__redis_client: RedisClient

__event_dispatcher: EventDispatcher
__exchange_consumer: IConsumer or None = None
__exchange_consumer: Optional[IConsumer] = None

__logger: Logger

Expand All @@ -66,7 +66,7 @@ def __init__(
redis_client: RedisClient,
logger: Logger,
event_dispatcher: EventDispatcher,
exchange_consumer: IConsumer or None = None,
exchange_consumer: Optional[IConsumer] = None,
) -> None:
Thread.__init__(self)

Expand Down Expand Up @@ -138,8 +138,8 @@ def is_healthy(self) -> bool:

def __receive(self, data: Dict) -> None:
try:
origin: ModuleOrigin or None = self.__validate_origin(origin=data.get("origin", None))
routing_key: RoutingKey or None = self.__validate_routing_key(
origin = self.__validate_origin(origin=data.get("origin", None))
routing_key = self.__validate_routing_key(
routing_key=data.get("routing_key", None),
)

Expand All @@ -149,7 +149,7 @@ def __receive(self, data: Dict) -> None:
and data.get("data", None) is not None
and isinstance(data.get("data", None), dict) is True
):
data: Dict or None = self.__validate_data(
data = self.__validate_data(
origin=origin,
routing_key=routing_key,
data=data.get("data", None),
Expand Down Expand Up @@ -180,7 +180,7 @@ def __receive(self, data: Dict) -> None:
# -----------------------------------------------------------------------------

@staticmethod
def __validate_origin(origin: str or None) -> ModuleOrigin or None:
def __validate_origin(origin: Optional[str]) -> Optional[ModuleOrigin]:
if (
origin is not None
and isinstance(origin, str) is True
Expand All @@ -193,7 +193,7 @@ def __validate_origin(origin: str or None) -> ModuleOrigin or None:
# -----------------------------------------------------------------------------

@staticmethod
def __validate_routing_key(routing_key: str or None) -> RoutingKey or None:
def __validate_routing_key(routing_key: Optional[str]) -> Optional[RoutingKey]:
if (
routing_key is not None
and isinstance(routing_key, str) is True
Expand Down
4 changes: 2 additions & 2 deletions redisdb_exchange_plugin/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"""

# Library dependencies
from typing import Dict
from typing import Dict, Optional
from exchange_plugin.publisher import IPublisher
from kink import inject
from modules_metadata.routing import RoutingKey
Expand Down Expand Up @@ -51,6 +51,6 @@ def __init__(

# -----------------------------------------------------------------------------

def publish(self, origin: ModuleOrigin, routing_key: RoutingKey, data: Dict or None) -> None:
def publish(self, origin: ModuleOrigin, routing_key: RoutingKey, data: Optional[Dict]) -> None:
"""Publish message to Redis exchange"""
self.__redis_client.publish(origin=origin, routing_key=routing_key, data=data)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
redis>=3.5
fastybird-exchange-plugin>=0.4
fastybird-modules-metadata>=0.7
fastybird-modules-metadata>=0.8
kink>=0.6
setuptools>=57.4
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def find_version(*file_paths):
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3 :: Only",
"Topic :: Communications",
"Topic :: Home Automation",
Expand Down

0 comments on commit dd5e84a

Please sign in to comment.