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

Commit 41818cd

Browse files
reivilibreDavid Robertson
andauthored
Fix type errors introduced by new annotations in the Prometheus Client library. (#11832)
Co-authored-by: David Robertson <[email protected]>
1 parent dd7f825 commit 41818cd

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

changelog.d/11832.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix type errors introduced by new annotations in the Prometheus Client library.

synapse/metrics/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
Type,
3131
TypeVar,
3232
Union,
33+
cast,
3334
)
3435

3536
import attr
@@ -60,14 +61,21 @@
6061
HAVE_PROC_SELF_STAT = os.path.exists("/proc/self/stat")
6162

6263

63-
class RegistryProxy:
64+
class _RegistryProxy:
6465
@staticmethod
6566
def collect() -> Iterable[Metric]:
6667
for metric in REGISTRY.collect():
6768
if not metric.name.startswith("__"):
6869
yield metric
6970

7071

72+
# A little bit nasty, but collect() above is static so a Protocol doesn't work.
73+
# _RegistryProxy matches the signature of a CollectorRegistry instance enough
74+
# for it to be usable in the contexts in which we use it.
75+
# TODO Do something nicer about this.
76+
RegistryProxy = cast(CollectorRegistry, _RegistryProxy)
77+
78+
7179
@attr.s(slots=True, hash=True, auto_attribs=True)
7280
class LaterGauge:
7381

synapse/python_dependencies.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@
7676
"msgpack>=0.5.2",
7777
"phonenumbers>=8.2.0",
7878
# we use GaugeHistogramMetric, which was added in prom-client 0.4.0.
79-
# 0.13.0 has an incorrect type annotation, see #11832.
80-
"prometheus_client>=0.4.0,<0.13.0",
79+
"prometheus_client>=0.4.0",
8180
# we use `order`, which arrived in attrs 19.2.0.
8281
# Note: 21.1.0 broke `/sync`, see #9936
8382
"attrs>=19.2.0,!=21.1.0",

0 commit comments

Comments
 (0)