Skip to content

Commit dba7d7b

Browse files
committed
Sharpen type annotation.
1 parent 7f0feb3 commit dba7d7b

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/clusterfuzz/_internal/system/environment.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import subprocess
2222
import sys
2323
from typing import Optional
24+
from typing import TypeVar
25+
from typing import Union
2426

2527
import yaml
2628

@@ -601,7 +603,12 @@ def get_ubsan_disabled_options():
601603
}
602604

603605

604-
def get_value_raw(var: str, default: Optional[str] = None) -> Optional[str]:
606+
# This allows the type checker to notice that if the default value passed to
607+
# `get_value_raw()` is not None, then the function will never return None.
608+
_MaybeStr = TypeVar('MaybeStr', bound=Optional[str])
609+
610+
611+
def get_value_raw(var: str, default: _MaybeStr = None) -> Union[str, _MaybeStr]:
605612
"""Returns environment variable `var` directly, without evaluating it."""
606613
return os.environ.get(var, default)
607614

0 commit comments

Comments
 (0)