|
5 | 5 |
|
6 | 6 |
|
7 | 7 | import asyncio
|
8 |
| -import typing |
9 | 8 | from collections.abc import Callable, ItemsView, Iterator, KeysView, Mapping, ValuesView
|
| 9 | +from typing import Hashable, TypeVar, overload |
10 | 10 |
|
11 | 11 | from typing_extensions import override
|
12 | 12 |
|
13 | 13 | from .._receiver import Receiver
|
14 | 14 |
|
15 |
| -ValueT_co = typing.TypeVar("ValueT_co", covariant=True) |
| 15 | +ValueT_co = TypeVar("ValueT_co", covariant=True) |
16 | 16 | """Covariant type variable for the values cached by the `GroupingLatestValueCache`."""
|
17 | 17 |
|
18 |
| -DefaultT = typing.TypeVar("DefaultT") |
| 18 | +DefaultT = TypeVar("DefaultT") |
19 | 19 | """Type variable for the default value returned by `GroupingLatestValueCache.get`."""
|
20 | 20 |
|
21 |
| -HashableT = typing.TypeVar("HashableT", bound=typing.Hashable) |
| 21 | +HashableT = TypeVar("HashableT", bound=Hashable) |
22 | 22 | """Type variable for the keys used to group values in the `GroupingLatestValueCache`."""
|
23 | 23 |
|
24 | 24 |
|
@@ -126,12 +126,12 @@ def values(self) -> ValuesView[ValueT_co]:
|
126 | 126 | """Return an iterator over the latest values received."""
|
127 | 127 | return self._latest_value_by_key.values()
|
128 | 128 |
|
129 |
| - @typing.overload |
| 129 | + @overload |
130 | 130 | def get(self, key: HashableT, default: None = None) -> ValueT_co | None:
|
131 | 131 | """Return the latest value that has been received for a specific key."""
|
132 | 132 |
|
133 | 133 | # MyPy passes this overload as a valid signature, but pylint does not like it.
|
134 |
| - @typing.overload |
| 134 | + @overload |
135 | 135 | def get( # pylint: disable=signature-differs
|
136 | 136 | self, key: HashableT, default: DefaultT
|
137 | 137 | ) -> ValueT_co | DefaultT:
|
@@ -228,11 +228,11 @@ def __delitem__(self, key: HashableT) -> None:
|
228 | 228 | """
|
229 | 229 | del self._latest_value_by_key[key]
|
230 | 230 |
|
231 |
| - @typing.overload |
| 231 | + @overload |
232 | 232 | def pop(self, key: HashableT, /) -> ValueT_co | None:
|
233 | 233 | """Remove the latest value for a specific key and return it."""
|
234 | 234 |
|
235 |
| - @typing.overload |
| 235 | + @overload |
236 | 236 | def pop(self, key: HashableT, /, default: DefaultT) -> ValueT_co | DefaultT:
|
237 | 237 | """Remove the latest value for a specific key and return it."""
|
238 | 238 |
|
|
0 commit comments