Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit a0aef0b

Browse files
committed
Back out of generics due to python-attrs/attrs#313
1 parent 9444ca1 commit a0aef0b

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

synapse/util/async_helpers.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -550,16 +550,18 @@ def failure_cb(val):
550550
return new_d
551551

552552

553+
# This class can't be generic because it uses slots with attrs.
554+
# See: https://github.com/python-attrs/attrs/issues/313
553555
@attr.s(slots=True, frozen=True)
554-
class DoneAwaitable(Generic[R]):
556+
class DoneAwaitable: # should be: Generic[R]
555557
"""Simple awaitable that returns the provided value."""
556558

557-
value = attr.ib(type="R")
559+
value = attr.ib(type=Any) # should be: R
558560

559561
def __await__(self):
560562
return self
561563

562-
def __iter__(self) -> "DoneAwaitable[R]":
564+
def __iter__(self) -> "DoneAwaitable":
563565
return self
564566

565567
def __next__(self) -> None:

synapse/util/caches/dictionary_cache.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import enum
1515
import logging
1616
import threading
17-
from typing import Dict, Generic, Iterable, Optional, Set, TypeVar
17+
from typing import Any, Dict, Generic, Iterable, Optional, Set, TypeVar
1818

1919
import attr
2020

@@ -31,8 +31,10 @@
3131
DV = TypeVar("DV")
3232

3333

34+
# This class can't be generic because it uses slots with attrs.
35+
# See: https://github.com/python-attrs/attrs/issues/313
3436
@attr.s(slots=True)
35-
class DictionaryEntry(Generic[DKT, DV]):
37+
class DictionaryEntry: # should be: Generic[DKT, DV].
3638
"""Returned when getting an entry from the cache
3739
3840
Attributes:
@@ -45,8 +47,8 @@ class DictionaryEntry(Generic[DKT, DV]):
4547
"""
4648

4749
full = attr.ib(type=bool)
48-
known_absent = attr.ib(type=Set[DKT])
49-
value = attr.ib(type=Dict[DKT, DV])
50+
known_absent = attr.ib(type=Set[Any]) # should be: Set[DKT]
51+
value = attr.ib(type=Dict[Any, Any]) # should be: Dict[DKT, DV]
5052

5153
def __len__(self) -> int:
5254
return len(self.value)
@@ -64,7 +66,7 @@ class DictionaryCache(Generic[KT, DKT, DV]):
6466
"""
6567

6668
def __init__(self, name: str, max_entries: int = 1000):
67-
self.cache: LruCache[KT, DictionaryEntry[DKT, DV]] = LruCache(
69+
self.cache: LruCache[KT, DictionaryEntry] = LruCache(
6870
max_size=max_entries, cache_name=name, size_callback=len
6971
)
7072

@@ -84,7 +86,7 @@ def check_thread(self) -> None:
8486

8587
def get(
8688
self, key: KT, dict_keys: Optional[Iterable[DKT]] = None
87-
) -> DictionaryEntry[DKT, DV]:
89+
) -> DictionaryEntry:
8890
"""Fetch an entry out of the cache
8991
9092
Args:
@@ -158,9 +160,7 @@ def _update_or_insert(
158160
# We pop and reinsert as we need to tell the cache the size may have
159161
# changed
160162

161-
entry: DictionaryEntry[DKT, DV] = self.cache.pop(
162-
key, DictionaryEntry(False, set(), {})
163-
)
163+
entry: DictionaryEntry = self.cache.pop(key, DictionaryEntry(False, set(), {}))
164164
entry.value.update(value)
165165
entry.known_absent.update(known_absent)
166166
self.cache[key] = entry

0 commit comments

Comments
 (0)