blob: ee52444e7828c1d2b7920749a800dbf77e653983 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
#!/usr/bin/env python3
import logging
from typing import Any, Optional
logger = logging.getLogger(__name__)
def unwrap_optional(x: Optional[Any]) -> Any:
"""Unwrap an Optional[Type] argument returning a Type value back.
If the Optional[Type] argument is None, however, raise an exception.
Use this to satisfy most type checkers that a value that could
be None isn't so as to drop the Optional.
"""
if x is None:
msg = 'Argument to unwrap_optional was unexpectedly None'
logger.critical(msg)
raise AssertionError(msg)
return x
|