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

Commit e97a34e

Browse files
author
David Robertson
committed
Fix mypy?
1 parent 5324ad0 commit e97a34e

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

synapse/events/validator.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
import collections.abc
15-
from typing import Iterable, Type, Union
15+
from typing import Iterable, Type, Union, cast
1616

1717
import jsonschema
1818

@@ -103,7 +103,12 @@ def validate_new(self, event: EventBase, config: HomeServerConfig) -> None:
103103
except jsonschema.ValidationError as e:
104104
if e.path:
105105
# example: "users_default": '0' is not of type 'integer'
106-
message = '"' + e.path[-1] + '": ' + e.message # noqa: B306
106+
# cast safety: path entries can be integers, if we fail to validate
107+
# items in an array. However the POWER_LEVELS_SCHEMA doesn't expect
108+
# to see any arrays.
109+
message = (
110+
'"' + cast(str, e.path[-1]) + '": ' + e.message # noqa: B306
111+
)
107112
# jsonschema.ValidationError.message is a valid attribute
108113
else:
109114
# example: '0' is not of type 'integer'

0 commit comments

Comments
 (0)