Skip to content

Commit d471c29

Browse files
authored
From typing import x (#12)
1 parent cb87665 commit d471c29

File tree

6 files changed

+17
-17
lines changed

6 files changed

+17
-17
lines changed

src/pgcachewatch/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import datetime
2-
import typing
2+
from typing import Literal, NewType
33

44
import pydantic
55

6-
OPERATIONS = typing.Literal[
6+
OPERATIONS = Literal[
77
"insert",
88
"update",
99
"delete",
1010
]
1111

12-
PGChannel = typing.NewType(
12+
PGChannel = NewType(
1313
"PGChannel",
1414
str,
1515
)

src/pgcachewatch/strategies.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import collections
22
import datetime
3-
import typing
3+
from typing import Callable, Protocol
44

55
from . import listeners, models, utils
66

77

8-
class Strategy(typing.Protocol):
8+
class Strategy(Protocol):
99
"""
1010
A protocol defining the clear method for different strategies.
1111
"""
@@ -26,7 +26,7 @@ def __init__(
2626
self,
2727
listener: listeners.EventQueueProtocol,
2828
settings: models.DeadlineSetting = models.DeadlineSetting(),
29-
predicate: typing.Callable[[models.Event], bool] = bool,
29+
predicate: Callable[[models.Event], bool] = bool,
3030
) -> None:
3131
super().__init__()
3232
self._listener = listener

src/pgcachewatch/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import asyncio
22
import datetime
33
import functools
4-
import typing
4+
from typing import Generator, Hashable
55

66
import asyncpg
77

88
from pgcachewatch import listeners, models
99

1010

1111
def make_key(
12-
args: tuple[typing.Hashable, ...],
12+
args: tuple[Hashable, ...],
1313
kwds: dict,
1414
typed: bool = False,
15-
) -> typing.Hashable:
15+
) -> Hashable:
1616
"""
1717
Create a cache key from the given function arguments and keyword arguments.
1818
"""
@@ -36,7 +36,7 @@ async def emit_event(
3636
def pick_until_deadline(
3737
queue: listeners.EventQueueProtocol,
3838
settings: models.DeadlineSetting,
39-
) -> typing.Iterator[models.Event]:
39+
) -> Generator[models.Event, None, None]:
4040
"""
4141
Yield events from the queue until the deadline is reached or queue is empty.
4242
"""

tests/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import os
2-
import typing
2+
from typing import AsyncGenerator
33

44
import asyncpg
55
import pytest
66

77

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

1616

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

tests/test_listeners.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import asyncio
22
import datetime
3-
import typing
3+
from typing import get_args
44

55
import asyncpg
66
import pytest
77
from pgcachewatch import listeners, models, utils
88

99

1010
@pytest.mark.parametrize("N", (4, 8, 32))
11-
@pytest.mark.parametrize("operation", typing.get_args(models.OPERATIONS))
11+
@pytest.mark.parametrize("operation", get_args(models.OPERATIONS))
1212
async def test_eventqueue_and_pglistner(
1313
N: int,
1414
operation: models.OPERATIONS,

tests/test_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import asyncio
22
import datetime
33
import time
4-
import typing
4+
from typing import get_args
55

66
import asyncpg
77
import pytest
88
from pgcachewatch import listeners, models, utils
99

1010

1111
@pytest.mark.parametrize("N", (1, 2, 8))
12-
@pytest.mark.parametrize("operation", typing.get_args(models.OPERATIONS))
12+
@pytest.mark.parametrize("operation", get_args(models.OPERATIONS))
1313
async def test_emit_event(
1414
N: int,
1515
operation: models.OPERATIONS,

0 commit comments

Comments
 (0)