@@ -278,39 +278,12 @@ def get_user_id() -> int | None:
278
278
return uid if uid != ERROR else None
279
279
280
280
281
- # Perform exhaustiveness checking.
282
- #
283
- # Consider this example:
284
- #
285
- # MyUnion = Union[int, str]
286
- #
287
- # def handle(x: MyUnion) -> int {
288
- # if isinstance(x, int):
289
- # return 1
290
- # elif isinstance(x, str):
291
- # return 2
292
- # else:
293
- # raise Exception('unreachable')
294
- #
295
- # Now suppose we add a new variant:
296
- #
297
- # MyUnion = Union[int, str, bytes]
298
- #
299
- # After doing this, we must remember ourselves to go and update the handle
300
- # function to handle the new variant.
301
- #
302
- # With `assert_never` we can do better:
303
- #
304
- # // raise Exception('unreachable')
305
- # return assert_never(x)
306
- #
307
- # Now, if we forget to handle the new variant, the type-checker will emit a
308
- # compile-time error, instead of the runtime error we would have gotten
309
- # previously.
310
- #
311
- # This also work for Enums (if you use `is` to compare) and Literals.
312
- def assert_never (value : NoReturn ) -> NoReturn :
313
- assert False , f"Unhandled value: { value } ({ type (value ).__name__ } )"
281
+ if sys .version_info >= (3 , 11 ):
282
+ from typing import assert_never
283
+ else :
284
+
285
+ def assert_never (value : NoReturn ) -> NoReturn :
286
+ assert False , f"Unhandled value: { value } ({ type (value ).__name__ } )"
314
287
315
288
316
289
class CallableBool :
0 commit comments