From 0a1c958d2695db610ec0d16a9486640b3fa3c9bb Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Mon, 20 Jul 2026 13:37:45 +0100 Subject: [PATCH] `unwrap` utility --- synapse/types/__init__.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/synapse/types/__init__.py b/synapse/types/__init__.py index a6fc806701..5678fcdc3b 100644 --- a/synapse/types/__init__.py +++ b/synapse/types/__init__.py @@ -1714,3 +1714,17 @@ class EventOrderings: stream = event.internal_metadata.stream_ordering assert stream is not None return EventOrderings(stream, event.depth) + + +def unwrap(val: T | None) -> T: + """ + Assert that a value is non-None. + + Analogous to `Option.unwrap` in Rust. + + Useful as an inline alternative to `assert val is not None`, + e.g. in set comprehensions. + """ + + assert val is not None + return val