From 9abb17197556416279ab79bd9dcc0bcb9763fc73 Mon Sep 17 00:00:00 2001 From: David Robertson Date: Sun, 29 May 2022 22:21:23 +0100 Subject: [PATCH] Fix mypy? --- synapse/events/validator.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/synapse/events/validator.py b/synapse/events/validator.py index 360d24274a52..a94257deed72 100644 --- a/synapse/events/validator.py +++ b/synapse/events/validator.py @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import collections.abc -from typing import Iterable, Type, Union +from typing import Iterable, Type, Union, cast import jsonschema @@ -103,7 +103,12 @@ def validate_new(self, event: EventBase, config: HomeServerConfig) -> None: except jsonschema.ValidationError as e: if e.path: # example: "users_default": '0' is not of type 'integer' - message = '"' + e.path[-1] + '": ' + e.message # noqa: B306 + # cast safety: path entries can be integers, if we fail to validate + # items in an array. However the POWER_LEVELS_SCHEMA doesn't expect + # to see any arrays. + message = ( + '"' + cast(str, e.path[-1]) + '": ' + e.message + ) # noqa: B306 # jsonschema.ValidationError.message is a valid attribute else: # example: '0' is not of type 'integer'