Comment 1 for bug 1706413

Revision history for this message
Robie Basak (racb) wrote :

I think that if we treat each checking function as returning a sequence of booleans, telling us whether each check was successful or not, then yielding works. You can interpret the results of any check function using all(), any() or examining the individual booleans. A check function can use "yield from" to incorporate other check functions, and each check function can adjust its control flow according to previous checks (for example if a check isn't possible because a previous check failed).

I prefer this because I think that using "ret" on every line is particularly error-prone. It's repetitive code, which I think is the code smell here.

I admit that perhaps it's not great for the returned booleans not to be aligned with anything. We could further enhance the results by making them class instances that define __bool__ instead, but also carry more information about what failed. This would work quite nicely to separate stdout from the running of the checks for better testability. yield and all() would still work. We'd do something like:

    yield LintError("X is not Y")

or:

    yield LintSuccess("A is correct")

LintSuccess.__bool__() would always return True, and LintError.__bool__() would always return False.