google / clusterfuzz

Scalable fuzzing infrastructure.
https://google.github.io/clusterfuzz
Apache License 2.0
5.29k stars 554 forks source link

Rename `environment.get_value_string()` to `get_value_raw()`. #4132

Open letitz opened 3 months ago

letitz commented 3 months ago

This is a prelude to fixing type errors in environment.py.

One of the big sources of type errors so far has been the fact that environment.get_value() is ~untyped. Many places in the codebase assume that it returns e.g. a string, or an int. We can introduce get_value_int() for example for ints that checks at runtime that the environment variable evaluated to an int, and use that instead where applicable to appease the type checker (and surface errors earlier at runtime).

There is a need for a get_value_string() that tries to evaluate environment variable contents, i.e. supports quoted values. Many variables are expected to be strings, yet the pervasive use of environment.get_value() and environment.set_value() means it is hard to tell whether they are sometimes quoted or not.

This PR renames the current get_value_string() function to make space for a future get_value_string() that evaluates variables.

letitz commented 1 month ago

Thanks for the review! I've rebased and made the type annotation more precise, to avoid errors like:

foo = environment.get_value_raw('foo', '')
bar = foo.split(',')   # type checker complains `foo` might be None