Skip to content

Commit

Permalink
From typing import x (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
janbjorge authored Feb 23, 2024
1 parent cb87665 commit d471c29
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/pgcachewatch/models.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import datetime
import typing
from typing import Literal, NewType

import pydantic

OPERATIONS = typing.Literal[
OPERATIONS = Literal[
"insert",
"update",
"delete",
]

PGChannel = typing.NewType(
PGChannel = NewType(
"PGChannel",
str,
)
Expand Down
6 changes: 3 additions & 3 deletions src/pgcachewatch/strategies.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import collections
import datetime
import typing
from typing import Callable, Protocol

from . import listeners, models, utils


class Strategy(typing.Protocol):
class Strategy(Protocol):
"""
A protocol defining the clear method for different strategies.
"""
Expand All @@ -26,7 +26,7 @@ def __init__(
self,
listener: listeners.EventQueueProtocol,
settings: models.DeadlineSetting = models.DeadlineSetting(),
predicate: typing.Callable[[models.Event], bool] = bool,
predicate: Callable[[models.Event], bool] = bool,
) -> None:
super().__init__()
self._listener = listener
Expand Down
8 changes: 4 additions & 4 deletions src/pgcachewatch/utils.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import asyncio
import datetime
import functools
import typing
from typing import Generator, Hashable

import asyncpg

from pgcachewatch import listeners, models


def make_key(
args: tuple[typing.Hashable, ...],
args: tuple[Hashable, ...],
kwds: dict,
typed: bool = False,
) -> typing.Hashable:
) -> Hashable:
"""
Create a cache key from the given function arguments and keyword arguments.
"""
Expand All @@ -36,7 +36,7 @@ async def emit_event(
def pick_until_deadline(
queue: listeners.EventQueueProtocol,
settings: models.DeadlineSetting,
) -> typing.Iterator[models.Event]:
) -> Generator[models.Event, None, None]:
"""
Yield events from the queue until the deadline is reached or queue is empty.
"""
Expand Down
6 changes: 3 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import os
import typing
from typing import AsyncGenerator

import asyncpg
import pytest


@pytest.fixture(scope="function")
async def pgconn() -> typing.AsyncGenerator[asyncpg.Connection, None]:
async def pgconn() -> AsyncGenerator[asyncpg.Connection, None]:
conn = await asyncpg.connect()
try:
yield conn
Expand All @@ -15,7 +15,7 @@ async def pgconn() -> typing.AsyncGenerator[asyncpg.Connection, None]:


@pytest.fixture(scope="function")
async def pgpool() -> typing.AsyncGenerator[asyncpg.Pool, None]:
async def pgpool() -> AsyncGenerator[asyncpg.Pool, None]:
async with asyncpg.create_pool() as pool:
yield pool

Expand Down
4 changes: 2 additions & 2 deletions tests/test_listeners.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import asyncio
import datetime
import typing
from typing import get_args

import asyncpg
import pytest
from pgcachewatch import listeners, models, utils


@pytest.mark.parametrize("N", (4, 8, 32))
@pytest.mark.parametrize("operation", typing.get_args(models.OPERATIONS))
@pytest.mark.parametrize("operation", get_args(models.OPERATIONS))
async def test_eventqueue_and_pglistner(
N: int,
operation: models.OPERATIONS,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import asyncio
import datetime
import time
import typing
from typing import get_args

import asyncpg
import pytest
from pgcachewatch import listeners, models, utils


@pytest.mark.parametrize("N", (1, 2, 8))
@pytest.mark.parametrize("operation", typing.get_args(models.OPERATIONS))
@pytest.mark.parametrize("operation", get_args(models.OPERATIONS))
async def test_emit_event(
N: int,
operation: models.OPERATIONS,
Expand Down

0 comments on commit d471c29

Please sign in to comment.