Skip to content

Commit

Permalink
♻️ Declare types in file instead of importing from types.py
Browse files Browse the repository at this point in the history
  • Loading branch information
odiseo0 committed Jun 19, 2022
1 parent 0fe4287 commit d81682a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
14 changes: 11 additions & 3 deletions realtime/connection.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
import sys
import asyncio
import json
import logging
from collections import defaultdict
from functools import wraps
from typing import Any, Callable, List, Dict, cast
from typing import Any, Callable, List, Dict, cast, TypeVar

if sys.version_info > (3, 9):
from typing import ParamSpec
else:
from typing_extensions import ParamSpec

import websockets

from realtime.channel import Channel
from realtime.exceptions import NotConnectedError
from realtime.message import HEARTBEAT_PAYLOAD, PHOENIX_CHANNEL, ChannelEvents, Message
from realtime.types import T_ParamSpec, T_Retval


T_Retval = TypeVar("T_Retval")
T_ParamSpec = ParamSpec("T_ParamSpec")

logging.basicConfig(
format="%(asctime)s:%(levelname)s - %(message)s", level=logging.INFO)


def ensure_connection(func: Callable[T_ParamSpec, T_Retval]):
@wraps(func)
def wrapper(*args: T_ParamSpec.args, **kwargs: T_ParamSpec.kwargs) -> T_Retval:
Expand Down
4 changes: 1 addition & 3 deletions realtime/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
from typing_extensions import ParamSpec


# Generic types
T = TypeVar("T")
T_Retval = TypeVar("T_Retval")
T_ParamSpec = ParamSpec("T_ParamSpec")
T_Retval = TypeVar("T_Retval")

# Custom types
Callback = Callable[T_ParamSpec, T_Retval]

0 comments on commit d81682a

Please sign in to comment.