From 9aabaacb86c8ec099c78ca5e754665af2fd03a13 Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Wed, 30 Oct 2024 22:14:21 +0000 Subject: [PATCH] convert self.PATTERNS to a List --- synapse/rest/client/reporting.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/synapse/rest/client/reporting.py b/synapse/rest/client/reporting.py index f18886eeef5..949f0770351 100644 --- a/synapse/rest/client/reporting.py +++ b/synapse/rest/client/reporting.py @@ -22,7 +22,7 @@ import logging import re from http import HTTPStatus -from typing import TYPE_CHECKING, Any, Pattern, Tuple, cast +from typing import TYPE_CHECKING, Tuple from synapse._pydantic_compat import StrictStr from synapse.api.errors import AuthError, Codes, NotFoundError, SynapseError @@ -110,11 +110,14 @@ class ReportRoomRestServlet(RestServlet): Introduced by MSC4151: https://github.com/matrix-org/matrix-spec-proposals/pull/4151 """ - PATTERNS = client_patterns( - "/rooms/(?P[^/]*)/report$", - releases=("v3",), - unstable=False, - v1=False, + # Cast the Iterable to a list so that we can `append` below. + PATTERNS = list( + client_patterns( + "/rooms/(?P[^/]*)/report$", + releases=("v3",), + unstable=False, + v1=False, + ) ) def __init__(self, hs: "HomeServer"): @@ -127,10 +130,7 @@ def __init__(self, hs: "HomeServer"): # TODO: Remove the unstable variant after 2-3 releases # https://github.com/element-hq/synapse/issues/17373 if hs.config.experimental.msc4151_enabled: - # XXX: We shouldn't be casting like this because we're relying on an - # implementation detail. This code *should* be temporary though, per - # above TODO, so is safe enough? - cast(self.PATTERNS, list[Pattern[Any]]).append( + self.PATTERNS.append( re.compile( f"^{CLIENT_API_PREFIX}/unstable/org.matrix.msc4151" "/rooms/(?P[^/]*)/report$"