diff --git a/src/clusterfuzz/_internal/bot/tasks/utasks/fuzz_task.py b/src/clusterfuzz/_internal/bot/tasks/utasks/fuzz_task.py index e4c7b531bf..148ed37bb4 100644 --- a/src/clusterfuzz/_internal/bot/tasks/utasks/fuzz_task.py +++ b/src/clusterfuzz/_internal/bot/tasks/utasks/fuzz_task.py @@ -1172,11 +1172,10 @@ def key_fn(crash): def _get_issue_metadata_from_environment(variable_name): """Get issue metadata from environment.""" - values = str(environment.get_value_string(variable_name, '')).split(',') + values = environment.get_value_raw(variable_name, '').split(',') # Allow a variation with a '_1' to specified. This is needed in cases where # this is specified in both the job and the bot environment. - values.extend( - str(environment.get_value_string(variable_name + '_1', '')).split(',')) + values.extend(environment.get_value_raw(variable_name + '_1', '').split(',')) return [value.strip() for value in values if value.strip()] diff --git a/src/clusterfuzz/_internal/system/environment.py b/src/clusterfuzz/_internal/system/environment.py index b726c91684..356fd17174 100644 --- a/src/clusterfuzz/_internal/system/environment.py +++ b/src/clusterfuzz/_internal/system/environment.py @@ -20,6 +20,9 @@ import socket import subprocess import sys +from typing import Optional +from typing import TypeVar +from typing import Union import yaml @@ -600,9 +603,14 @@ def get_ubsan_disabled_options(): } -def get_value_string(environment_variable, default_value=None): - """Get environment variable (as a string).""" - return os.getenv(environment_variable, default_value) +# This allows the type checker to notice that if the default value passed to +# `get_value_raw()` is not None, then the function will never return None. +_MaybeStr = TypeVar('MaybeStr', bound=Optional[str]) + + +def get_value_raw(var: str, default: _MaybeStr = None) -> Union[str, _MaybeStr]: + """Returns environment variable `var` directly, without evaluating it.""" + return os.environ.get(var, default) def get_value(environment_variable, default_value=None, env=None):